H,我想在我的网络应用程序中升级Spring库.由于我也在使用Hibernate,我想知道是否有一种方法可以找到哪个版本的Hibernate与特定版本的Spring兼容.
我已经搜索了谷歌并阅读了类似的SO帖子,但我想知道是否有办法比较不同版本的库/框架.
我目前的设置:
Spring V2.5
Hibernate : org.hibernate.hibernate 3.2.6.ga
org.hibernate.hibernate-annotations 3.3.1.ga
Run Code Online (Sandbox Code Playgroud)
可用的最新版本的Hibernate在我的仓库是3.5.4-FINAL和3.5.6-FINAL为上述文物
更新 我使用Spring 2.5将Hibernate从3.2升级到3.5.4后出现此错误(未更改)
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor#0'
defined in class path resource [applicationContext-hibernate.xml]: Initialization of bean failed;
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory'
defined in class path resource [applicationContext-hibernate.xml]: Invocation of init method failed; nested exception is java.lang.IncompatibleClassChangeError:
Implementing class
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:480)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
at java.security.AccessController.doPrivileged(Native Method)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:221)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185) …Run Code Online (Sandbox Code Playgroud) 我将 log4j 依赖项升级到最新的 2.15.0 版本,现在我的 Spring Boot 应用程序在启动时抛出错误
Exception in thread "main" java.lang.NoSuchFieldError: EMPTY_BYTE_ARRAY
at org.apache.logging.log4j.core.config.ConfigurationSource.<clinit>(ConfigurationSource.java:56)
at org.apache.logging.log4j.core.config.NullConfiguration.<init>(NullConfiguration.java:32)
at org.apache.logging.log4j.core.LoggerContext.<clinit>(LoggerContext.java:85)
at org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.createContext(ClassLoaderContextSelector.java:254)
at org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.locateContext(ClassLoaderContextSelector.java:218)
at org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.getContext(ClassLoaderContextSelector.java:136)
at org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.getContext(ClassLoaderContextSelector.java:123)
at org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.getContext(ClassLoaderContextSelector.java:117)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:150)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:47)
at org.apache.logging.log4j.LogManager.getContext(LogManager.java:194)
at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:581)
at foo.bar.org.MyApp.<clinit>(MyApp.java:13)
Run Code Online (Sandbox Code Playgroud)
这是我的主要课程
@Log4j2
@SpringBootApplication(exclude={DataSourceAutoConfiguration.class})
public class MyApp {
public static void main(String[] args) {
SpringApplication.run(MyApp.class, args);
}
}
Run Code Online (Sandbox Code Playgroud) 我试图在我的spring应用程序中集成Quartz作业.我从这里得到了这个例子.该示例显示了使用a simpletrigger和在特定时间使用a 以重复间隔执行的作业crontrigger.
我的要求是在应用程序启动时只运行一次作业.我删除了属性repeatInterval,但应用程序抛出异常:
org.quartz.SchedulerException: Repeat Interval cannot be zero
Run Code Online (Sandbox Code Playgroud)
有没有办法安排一次工作?
谢谢..
我想知道是否有一种方法可以在CQ5中获取页面节点的呈现HTML输出,而无需点击实际的URL.我有页面节点,我想在java中以编程方式获取该页面节点的呈现HTML输出,并将其存储在字符串中,而不会访问页面URL.
任何帮助表示赞赏,提前谢谢!
我正在使用Session.save()方法(在Hibernate中)来持久化我返回类型对象的实体对象java.io.Serializable.
返回的值是实体生成的主键.
生成的主键是类型long(或bigint).
问题是:如何将返回值转换或转换为long?
Serializable result = session.save(myEntityObject);
//This line of code fails.
long r = (long)result;
Run Code Online (Sandbox Code Playgroud) 我有一个日期时间字符串"2018-01-15 01:16:00",它位于EST时区.我想使用UTC偏移动态地将其转换为另一个时区.我的javascript代码将此UTC偏移量作为参数传递,并且servlet必须将此日期时间字符串转换/格式化为由提供的偏移量标识的时区.
我尝试了很多方法,包括oracle教程中记录的方法,但无法找到解决方案.
以下是我正在尝试的代码,非常感谢任何帮助.
private static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
private static final String DEFAULT_TIME_ZONE = ZoneId.SHORT_IDS.get("EST");
public static void main(String[] args) throws Exception {
String dateTime = "2018-01-15 02:35:00";
//parse the datetime using LocalDateTime
LocalDateTime defaultDateTime = LocalDateTime.parse(dateTime, DateTimeFormatter.ofPattern(DATE_FORMAT));
//get the datetime in default timezone
ZoneId defaultZoneId = ZoneId.of(DEFAULT_TIME_ZONE);
ZonedDateTime defaultZoneDateTime = defaultDateTime.atZone(defaultZoneId);
System.out.println("EST time: "+defaultZoneDateTime.format(DateTimeFormatter.ofPattern(DATE_FORMAT)));
ZonedDateTime utcZonedDateTime = defaultZoneDateTime.withZoneSameInstant(ZoneId.of("UTC"));
String utcTime = defaultZoneDateTime.withZoneSameInstant(ZoneId.of("UTC")).format(DateTimeFormatter.ofPattern(DATE_FORMAT));
System.out.println("UTC : "+utcTime);
//IST timezone
ZoneOffset offset = ZoneOffset.of("+05:30");
OffsetDateTime offsetDate …Run Code Online (Sandbox Code Playgroud) 我试图在AEM上公开一些RESTfull Web服务.我已按照此博客中的说明操作.以下是我的服务类.像/ helloservice/sayhi这样的简单请求工作得很好,但是采用路径参数和查询参数的方法(/withparameter/{userid}和/query?q=xyz&prod=abc)返回404错误页面.请帮我解决一下这个.
我正在使用AEM 5.6和Java 7
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Service;
import com.foo.bar.service.SampleResource;
@Service
@Component(metatype=true)
@Path("/helloservice")
public class SampleResourceImpl implements SampleResource{
@GET
@Path("/sayhi")
@Produces({MediaType.APPLICATION_JSON})
public String helloWorld(){
return "Hello World";
}
@GET
@Path("/getoperation")
@Produces({MediaType.TEXT_PLAIN})
public String getServiceOperation(){
return "Hello getoperation!";
}
@GET
@Path("/withparameter/{userid}")
@Produces({MediaType.TEXT_PLAIN})
public String getWithParameter(@PathParam("userid") String userid){
return "Path parameter : "+userid;
}
@GET
@Path("/query")
@Produces({MediaType.TEXT_PLAIN})
public String getURLParameters(@QueryParam("q") String q, …Run Code Online (Sandbox Code Playgroud) 我试图单元测试从vertx一个HTTP调用WebClientuing VertxUnitRunner和vertx的RXified版本.
问题是我的单元测试总是因超时异常而失败.是否有不同的单元测试WebClienthttp调用方式?以下是我的代码:
import io.vertx.core.AsyncResult;
import io.vertx.core.http.HttpClientOptions;
import io.vertx.core.http.HttpServerOptions;
import io.vertx.ext.unit.TestContext;
import io.vertx.ext.unit.junit.VertxUnitRunner;
import io.vertx.rxjava.core.Vertx;
import io.vertx.rxjava.core.buffer.Buffer;
import io.vertx.rxjava.core.http.HttpServer;
import io.vertx.rxjava.ext.web.client.HttpResponse;
import io.vertx.rxjava.ext.web.client.WebClient;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import rx.Single;
@RunWith(VertxUnitRunner.class)
public class MyVertxTest {
private Vertx vertx;
private WebClient client;
@Before
public void setUp() throws Exception {
vertx = Vertx.vertx();
}
@Test
public void testGetContactDetails(TestContext context) {
System.out.println("start");
long start = System.currentTimeMillis();
HttpServer server = vertx.createHttpServer(new HttpServerOptions().setPort(TEST_SERVER_PORT));
server.requestStream().handler(req -> {
req.response().setChunked(true).write("foo bar").end();
}); …Run Code Online (Sandbox Code Playgroud) 我不太确定这个方法做了什么,或者更好,我不确定":"是什么意思.有人可以帮我理解吗?
private int guess( )
{
return isTrue( ) ? A : isFalse( ) ? B : neither( ) ? C : D;
}
Run Code Online (Sandbox Code Playgroud) public Object getValue()
{
ValueItem valueItem = null;
Object returnValue = null;
if(this.value instanceof StringValueImpl)
{
valueItem = (StringValueImpl) this.value;
}
else if(this.value instanceof ListValueImpl)
{
valueItem = (ListValueImpl) this.value;
}
else if(this.value instanceof MapValueImpl)
{
valueItem = (MapValueImpl) this.value;
}
if(valueItem!=null)
returnValue = valueItem.getValue();
return returnValue;
}
Run Code Online (Sandbox Code Playgroud)
ValueItem是的interface这是由执行ListValueImpl,MapValueImpl等等.我想返回值是一个object.代码工作正常但我想知道这是否可以以任何方式改进?
这是面试问题之一.我应该在命令行上打印多行输出,而不使用\njava中的newline()字符.我试着谷歌搜索,没有找到合适的答案.如果我打印5个数字,则应按以下方式打印.但我不应该使用换行符也不应该循环.我把它打印出来使用单个 println()语句.你能给我一些想法吗?谢谢 !
1
2
3
4
5
Run Code Online (Sandbox Code Playgroud) 我知道在java中传递对象时,对象的引用作为值传递.因此,您对该对象所做的更改也会反映在原始对象中.为避免这种情况,我们在java中使用immutability属性.
所以我的问题是,我创建了一个不可变类Employee,当我将这个Employee类的对象传递给其他类中的某个方法时,我不希望该方法对该对象进行任何更改.即使它确实如此,我也不希望更改受到调用类中创建的原始对象的影响.
这是我的示例代码.
public final class Employee {
int employeeId;
public int getId() {
return employeeId;
}
public void setId(int id) {
this.employeeId = id;
}
}
public class Worker {
public static void process(Employee f, Employee g){
int c = f.getId();
f.setId(g.getId());
g.setId(c);
}
}
public class ImmutabilityTest{
public static void main(String[] args) {
Employee teamMember = new Employee();
Employee teamLead = new Employee();
teamMember.setId(5);
teamLead.setId(10);
System.out.println("Before process "+teamMember.getId() + " " + …Run Code Online (Sandbox Code Playgroud) 我现在很喜欢编程和学习java.我写了下面的代码但是我没有得到正确的结果: -
public class LifeTime {
public static void main(String[] args) {
int x;
for(x = 0; x < 3 ; x++); {
int y = -1; //y is initialized each time block is entered
System.out.println("y is : " + y); // this always prints -1
y = 100;
System.out.println("Y is : " + y);
}
}
}
Run Code Online (Sandbox Code Playgroud)
结果如下: -
y是:-1 Y是:100
直到3还有重复,为什么?
在我编写的所有循环程序中都观察到相同的行为
你能帮忙吗?