springframework.beans.factory.BeanCreationException:创建名称为' entityManagerFactory'的bean时出错在com.navin.friends.config.JPAConfig中定义:调用init方法失败;嵌套异常是java.lang.IllegalStateException:必须从Java代理开始才能使用InstrumentationLoadTimeWeaver。请参阅Spring文档。 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1578)〜[spring-beans-4.2.3.RELEASE.jar:4.2.3.RELEASE] 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545)〜[spring-beans-4.2.3.RELEASE.jar:4.2.3.RELEASE] 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)〜[spring-beans-4.2.3.RELEASE.jar:4.2.3.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory $ 1.getObject(AbstractBeanFactory.java:306)〜[spring-beans-4.2.3.RELEASE.jar:4.2.3.RELEASE] 在org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)〜[spring-beans-4.2.3.RELEASE.jar:4.2.3.RELEASE] 在org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)〜[spring-beans-4.2.3.RELEASE.jar:4.2.3.RELEASE] 在org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)〜[spring-beans-4.2.3.RELEASE.jar:4.2.3.RELEASE] 在org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1051)〜[spring-context-4.2.3.RELEASE.jar:4.2.3.RELEASE] 在org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:828)〜[spring-context-4.2.3.RELEASE.jar:4.2.3.RELEASE] 在org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:537)〜[spring-context-4.2.3.RELEASE.jar:4.2.3.RELEASE] 在org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:446)〜[spring-web-4.2.3.RELEASE.jar:4.2.3.RELEASE] 在org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:328)〜[spring-web-4.2.3.RELEASE.jar:4.2.3.RELEASE] 在org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107)[spring-web-4.2.3.RELEASE.jar:4.2.3.RELEASE] at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4791)[tomcat-embed-core-7.0.30.jar:7.0.30] at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5285)[tomcat-embed-core-7.0.30.jar:7.0.30] 在org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)[tomcat-embed-core-7.0.30.jar:7.0.30] 在org.apache.catalina.core.ContainerBase $ StartChild.call(ContainerBase.java:1559)[tomcat-embed-core-7.0.30.jar:7.0.30] 在org.apache.catalina.core.ContainerBase $ StartChild.call(ContainerBase.java:1549)[tomcat-embed-core-7.0.30.jar:7.0.30] at java.util.concurrent.FutureTask.run(FutureTask.java:266)[na:1.8.0_91] 在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)[na:1.8.0_91] at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:617)[na:1.8.0_91] 在java.lang.Thread.run(Thread.java:745)[na:1.8.0_91] 引起:java.lang.IllegalStateException:必须从Java代理开始才能使用InstrumentationLoadTimeWeaver。请参阅Spring文档。 在org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver.addTransformer(InstrumentationLoadTimeWeaver.java:88)〜[spring-context-4.2.3.RELEASE.jar:4.2.3.RELEASE] 在org.springframework.orm.jpa.persistenceunit.SpringPersistenceUnitInfo.addTransformer(SpringPersistenceUnitInfo.java:82)〜[spring-orm-4.2.3.RELEASE.jar:4.2.3.RELEASE] 在org.eclipse.persistence.jpa.PersistenceProvider.createContainerEntityManagerFactory(PersistenceProvider.java:348)〜[eclipselink-2.5.0.jar:2.5.0.v20130507-3faac2b] 在org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:343)〜[spring-orm-4.2.3.RELEASE.jar:4.2.3.RELEASE] 在org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:318)〜[spring-orm-4.2.3.RELEASE.jar:4.2.3.RELEASE] 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637)〜[spring-beans-4.2.3.RELEASE.jar:4.2.3.RELEASE] 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)〜[spring-beans-4.2.3.RELEASE.jar:4.2.3.RELEASE] ...省略了21个常用帧 2017年6月1日下午5:53:26 org.apache.catalina.core.StandardContext listenerStart SEVERE:将上下文初始化事件发送到类org.springframework.web.context.ContextLoaderListener的侦听器实例的异常 org.springframework.beans.factory.BeanCreationException:使用名称' entityManagerFactory'创建bean时出错。在com.navin.friends.config.JPAConfig中定义:调用init方法失败;嵌套异常是java.lang.IllegalStateException:必须从Java代理开始才能使用InstrumentationLoadTimeWeaver。请参阅Spring文档。 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1578) 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545) 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) at org.springframework.beans.factory.support.AbstractBeanFactory $ 1.getObject(AbstractBeanFactory.java:306) 在org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) 在org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) 在org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) 在org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1051) 在org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:828) 在org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:537) 在org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:446) 在org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:328) 在org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107) 在org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4791) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5285) 在org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) 在org.apache.catalina.core.ContainerBase $ StartChild.call(ContainerBase.java:1559) 在org.apache.catalina.core.ContainerBase $ StartChild.call(ContainerBase.java:1549) at java.util.concurrent.FutureTask.run(FutureTask.java:266) 在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:617) 在java.lang.Thread.run(Thread.java:745) 引起:java.lang.IllegalStateException:必须从Java代理开始才能使用InstrumentationLoadTimeWeaver。请参阅Spring文档。 在org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver.addTransformer(InstrumentationLoadTimeWeaver.java:88) 在org.springframework.orm.jpa.persistenceunit.SpringPersistenceUnitInfo.addTransformer(SpringPersistenceUnitInfo.java:82) 在org.eclipse.persistence.jpa.PersistenceProvider.createContainerEntityManagerFactory(PersistenceProvider.java:348) 在org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:343) 在org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:318) 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637) 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574) ......还有21个
Jun 01, 2017 5:53:26 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Error listenerStart
Jun 01, 2017 5:53:26 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Context [/remember-friends] startup failed due to previous errors
Jun 01, 2017 5:53:26 PM org.apache.catalina.core.ApplicationContext log
INFO: Closing Spring root WebApplicationContext
Jun 01, 2017 5:53:26 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [/remember-friends] appears to have started a thread named [Timer-0] but has failed to stop it. This is very likely to create a memory leak.
Jun 01, 2017 5:53:26 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-9090"]
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() throws IOException {
EclipseLinkJpaVendorAdapter vendorAdapter = new EclipseLinkJpaVendorAdapter();
vendorAdapter.setShowSql(true);
LocalContainerEntityManagerFactoryBean entityManagerFacotryBean= new LocalContainerEntityManagerFactoryBean();
entityManagerFacotryBean.setJpaVendorAdapter(vendorAdapter);
entityManagerFacotryBean.setDataSource(getDataSource());
entityManagerFacotryBean.setPackagesToScan("com.navin.friends.domain.entity");
entityManagerFacotryBean.setJpaProperties(getJPAProperties());
entityManagerFacotryBean.setLoadTimeWeaver(new InstrumentationLoadTimeWeaver());
entityManagerFacotryBean.setPersistenceUnitName("friends");
entityManagerFacotryBean.setJpaDialect(new EclipseLinkJpaDialect());
return entityManagerFacotryBean;
}
答案 0 :(得分:0)
您需要将spring-instrument.jar代理包含为:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.4</version>
<configuration>
<forkMode>once</forkMode>
<argLine>
-javaagent:"${settings.localRepository}/org/springframework/spring-instrument/${spring.framework.version}/spring-instrument-${spring.framework.version}.jar"
</argLine>
<useSystemClassloader>true</useSystemClassloader>
</configuration>
</plugin>
(用您的值替换$ {spring.framework.version}和$ {settings.localRepository})
当然还有一个AspecJ Maven插件:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.3</version>
<executions>
<execution>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
<goals>
<goal>compile</goal> <!-- use this goal to weave all your main classes -->
<goal>test-compile</goal> <!-- use this goal to weave all your test classes -->
</goals>
</execution>
</executions>
</plugin>
要使AspectJ正常工作,您还需要添加一个Aspectjrt依赖项:
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>${aspectjrt.version}</version>
</dependency>