Spring 4 LTW不兼容64位JVM和Tomcat



作为迁移到Java 8和纪念Spring 4的一部分,我认为我应该升级到所有64位代码。这个应用程序在32位上运行得很好,但是加载时间编织在64位上不工作(实际上甚至不加载)。

架构细节:

    Java 8.0.5(32位或64位视情况而定)
  • Tomcat 7.0.54(32位或64位)
  • 春天你
  • Eclipselink 2.5.1

在Spring Tool Suite 3.5.1下测试。部署目标RHEL

JVM启动:

-javaagent:C:Users....m2repositoryorgspringframeworkspring-instrument4.0.5.RELEASEspring-instrument-4.0.5.RELEASE.jar 

冒犯的Bean:

@Bean()
public LoadTimeWeaver loadTimeWeaver() {
    return new org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver();
}

错误非常简单:

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean 
with name 'entityManagerFactory' defined in class path resource com/xxxx/config/DataContextConfig.class]: 
Invocation of init method failed; nested exception is java.lang.IllegalStateException: 
Must start with Java agent to use InstrumentationLoadTimeWeaver. See Spring documentation.

我所做的只是更改为64位JVM并使用64位Tomcat容器。我在谷歌上搜索了很长时间,尝试了不同的版本和代理,但完全没有找到任何解决方案。谢谢。

更新:

这是一个标准的Eclipse服务器配置,所以我认为这基本上意味着startup.sh start。其他JVM属性如下所示。请注意,此时我们没有部署任何AspectJ方面,这是下一个版本。无论是否指定了AspectJ编织器,结果都是相同的。

-javaagent:C:UsersXXXXXX.m2repositoryorgspringframeworkspring-instrument4.0.5.RELEASEspring-instrument-4.0.5.RELEASE.jar
-javaagent:C:UsersXXXXXX.m2repositoryorgaspectjaspectjweaver1.8.0aspectjweaver-1.8.0.jar
-Dcatalina.base="C:UsersXXXXXXapache-tomcat-7.0.54-64bit"
-Dcatalina.home="C:UsersXXXXXXapache-tomcat-7.0.54-64bit"
-Dwtp.deploy="C:UsersXXXXXXapache-tomcat-7.0.54-64bitwebapps"
-Djava.endorsed.dirs="C:UsersXXXXXXapache-tomcat-7.0.54-64bitendorsed"   
异常堆栈

:

20140529 13:25:48,873 localhost-startStop-1 ERROR Context initialization failed
org.springframework.beans.factory.BeanCreationException:
    Error creating bean with name 'ieexbContextConfig': Injection of autowired dependencies failed;
    nested exception is org.springframework.beans.factory.BeanCreationException:
        Could not autowire field: com.xxx.yyyy.domain.FlowController com.xxx.yyyy.config.IeexbContextConfig.flowController;
        nested exception is org.springframework.beans.factory.BeanCreationException:
            Error creating bean with name 'FlowController': Injection of autowired dependencies failed;
            nested exception is org.springframework.beans.factory.BeanCreationException:
                Could not autowire field: com.xxx.yyyy.repository.PendingQueueRepository com.xxx.yyyy.domain.FlowController.pendingQueueRepository;
                    nested exception is org.springframework.beans.factory.BeanCreationException:
                        Error creating bean with name 'pend ingQueueRepository': Cannot create inner bean '(inner bean)#63244fdb' of type [org.springframework.orm.jpa.SharedEntityM anagerCreator] while setting bean property 'entityManager';
                        nested exception is org.springframework.beans.factory.BeanCreationException:
                            Error creating bean with name '(inner bean)#63244fdb': Cannot resolve reference to bean 'entityManagerF actory' while setting constructor argument;
                            nested exception is org.springframework.beans.factory.BeanCreationException:
                                Error creating bean with name 'entityManagerFactory' defined in class path resource [com/xxx/yyyy/config/IeexbDataCont extConfig.class]: Invocation of init method failed;
                                    nested exception is java.lang.IllegalStateException: Must start with Java agent to use InstrumentationLoadTimeWeaver. See Spring documentation.
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:292)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1185)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:703)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4973)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5467)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:632)
    at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1247)
    at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1898)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.xxx.yyyy.domain.FlowController com.xxx.yyyy.config.IeexbContextConfig.flowController; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'FlowController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.xxx.yyyy.repository.PendingQueueRepository com.xxx.yyyy.domain.FlowController.pendingQueueRepository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'pendingQueueRepository': Cannot create inner bean '(inner bean)#63244fdb' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property 'entityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#63244fdb': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [com/xxx/yyyy/config/IeexbDataContextConfig.class]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: Must start with Java agent to use InstrumentationLoadTimeWeaver. See Spring documentation.
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:508)
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:289)
    ... 26 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'FlowController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.xxx.yyyy.repository.PendingQueueRepository com.xxx.yyyy.domain.FlowController.pendingQueueRepository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'pendingQueueRepository': Cannot create inner bean '(inner bean)#63244fdb' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property 'entityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#63244fdb': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [com/xxx/yyyy/config/IeexbDataContextConfig.class]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: Must start with Java agent to use InstrumentationLoadTimeWeaver. See Spring documentation.
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:292)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1185)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1017)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:960)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:858)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:480)
    ... 28 more
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.xxx.yyyy.repository.PendingQueueRepository com.xxx.yyyy.domain.FlowController.pendingQueueRepository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'pendingQueueRepository': Cannot create inner bean '(inner bean)#63244fdb' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property 'entityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#63244fdb': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [com/xxx/yyyy/config/IeexbDataContextConfig.class]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: Must start with Java agent to use InstrumentationLoadTimeWeaver. See Spring documentation.
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:508)
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:289)
    ... 39 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'pendingQueueRepository': Cannot create inner bean '(inner bean)#63244fdb' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property 'entityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#63244fdb': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [com/xxx/yyyy/config/IeexbDataContextConfig.class]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: Must start with Java agent to use InstrumentationLoadTimeWeaver. See Spring documentation.
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:290)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:129)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1456)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1197)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1017)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:960)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:858)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:480)
    ... 41 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#63244fdb': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [com/xxx/yyyy/config/IeexbDataContextConfig.class]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: Must start with Java agent to use InstrumentationLoadTimeWeaver. See Spring documentation.
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:336)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108)
    at org.springframework.beans.factory.support.ConstructorResolver.resolveConstructorArguments(ConstructorResolver.java:632)
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:442)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1094)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:989)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:276)
    ... 54 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [com/xxx/yyyy/config/IeexbDataContextConfig.class]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: Must start with Java agent to use InstrumentationLoadTimeWeaver. See Spring documentation.
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1553)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
    ... 62 more
Caused by: java.lang.IllegalStateException: Must start with Java agent to use InstrumentationLoadTimeWeaver. See Spring documentation.
    at org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver.addTransformer(InstrumentationLoadTimeWeaver.java:88)
    at org.springframework.orm.jpa.persistenceunit.SpringPersistenceUnitInfo.addTransformer(SpringPersistenceUnitInfo.java:82)
    at org.eclipse.persistence.jpa.PersistenceProvider.createContainerEntityManagerFactory(PersistenceProvider.java:348)
    at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:336)
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:318)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1612)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1549)
    ... 69 more

我遇到了同样的问题。但最终问题不是来自spring-data-jpa,而是Tomcat从7.0.47版本(一切正常)到7.0.5x和Tomcat 8的变化。

尝试从您的应用程序WEB-INF/lib中删除spring-instrument.jar代理(如果您使用的是Maven,则为该依赖项添加一个提供的作用域),这应该可以解决问题。

我在Java 8上的Tomcat 8.0.9服务器上运行一个带有Eclipselink 2.5.2和Spring -data-jpa 1.6.2的Spring 4.0.6应用程序,所有内容都是64位的。这两种编织方法(启动时的agent或Tomcat lib目录中的spring-instrument.jar)正在工作。

注意:请确保您使用的是aspectj 1.8.1 (Spring 4.0.6附带)

问题是spring-data-jpa的当前版本是1.5.1。该版本显然与64位不兼容——尽管它在32位Java 8和Tomcat的Spring 4中工作得很好。

解决方案是引入1.7.0的SNAPSHOT构建,它可以与Spring 4和64位兼容。看到spring-data-jpa项目站点的依赖关系和官方Repository POM元素。我不确定我是否会尝试将SNAPSHOT代码发布到我们的生产环境中。希望他们能尽快发布。

值得注意的是,Eclipselink 2.5.1完全是64位的。

最新更新