我有一个基于Spring BOOT的webservice,它使用Spring数据JPA连接到MySql DB。我能够毫无问题地运行和部署应用程序。
然而,当我运行Integration测试用例时,随着应用程序的配置,我面临一个异常( java.lang.NoSuchMethodError :javax.persistence.EntityManagerFactory.getMetamodel()Ljavax /持久性/元模型/元模型)
这将被触发,因为即将创建扩展JpaRepository接口的存储库bean。
当我检查EntityManagerFactory接口方法时,我找到了getMetaModel()方法。
版本
如果任何人都可以指出根本原因或进一步的调试步骤,那将会很有帮助。
++++++++++++++++++++++++++++++++++++++++++
测试类
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {ApplicationService.class, ApplicationServiceImpl.class})
@EnableTransactionManagement
@WebAppConfiguration public class IntegrationTestBase {
@Autowired
private ApplicationServiceImpl service;
..
}
异常
java.lang.IllegalStateException: Failed to load ApplicationContext
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124)
at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:83)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:117)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:83)
at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:228)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:230)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:289)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:291)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:249)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:89)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:193)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:119)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:234)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:74)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ApplicationServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private de.adclear.soa.integration.repository.ApplicationRepository de.adclear.soa.integration.ApplicationServiceImpl.ApplicationRepository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ApplicationRepository': Cannot resolve reference to bean 'jpaMappingContext' while setting bean property 'mappingContext'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jpaMappingContext': Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: javax.persistence.EntityManagerFactory.getMetamodel()Ljavax/persistence/metamodel/Metamodel;
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538)
at org.springframework.test.context.web.AbstractGenericWebContextLoader.loadContext(AbstractGenericWebContextLoader.java:133)
at org.springframework.test.context.web.AbstractGenericWebContextLoader.loadContext(AbstractGenericWebContextLoader.java:60)
at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:109)
at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:261)
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:98)
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:116)
... 24 more
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private de.adclear.soa.integration.repository.ApplicationRepository de.adclear.soa.integration.ApplicationServiceImpl.ApplicationRepository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ApplicationRepository': Cannot resolve reference to bean 'jpaMappingContext' while setting bean property 'mappingContext'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jpaMappingContext': Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: javax.persistence.EntityManagerFactory.getMetamodel()Ljavax/persistence/metamodel/Metamodel;
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:573)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)
... 40 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ApplicationRepository': Cannot resolve reference to bean 'jpaMappingContext' while setting bean property 'mappingContext'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jpaMappingContext': Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: javax.persistence.EntityManagerFactory.getMetamodel()Ljavax/persistence/metamodel/Metamodel;
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:359)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1481)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1226)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1192)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1116)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1014)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:545)
... 42 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jpaMappingContext': Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: javax.persistence.EntityManagerFactory.getMetamodel()Ljavax/persistence/metamodel/Metamodel;
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1578)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:351)
... 55 more
Caused by: java.lang.NoSuchMethodError: javax.persistence.EntityManagerFactory.getMetamodel()Ljavax/persistence/metamodel/Metamodel;
at org.springframework.data.jpa.repository.config.JpaMetamodelMappingContextFactoryBean.getMetamodels(JpaMetamodelMappingContextFactoryBean.java:90)
at org.springframework.data.jpa.repository.config.JpaMetamodelMappingContextFactoryBean.createInstance(JpaMetamodelMappingContextFactoryBean.java:56)
at org.springframework.data.jpa.repository.config.JpaMetamodelMappingContextFactoryBean.createInstance(JpaMetamodelMappingContextFactoryBean.java:26)
at org.springframework.beans.factory.config.AbstractFactoryBean.afterPropertiesSet(AbstractFactoryBean.java:134)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:351)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1481)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1226)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1192)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1116)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1014)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:545)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538)
at org.springframework.test.context.web.AbstractGenericWebContextLoader.loadContext(AbstractGenericWebContextLoader.java:133)
at org.springframework.test.context.web.AbstractGenericWebContextLoader.loadContext(AbstractGenericWebContextLoader.java:60)
at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:109)
at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:261)
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:98)
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:116)
at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:83)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:117)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:83)
at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:228)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:230)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:289)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:291)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:249)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:89)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:193)
at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:283)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:173)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:153)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:128)
at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:203)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:155)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:103)
执行单元测试时,我会记录Spring配置和步骤的步骤。初始化,在这些步骤之后抛出异常 -
2016-06-06 11:35:51,840 INFO DebugSpringConfig:18 - postProcessBeforeInitialization: bean(ApplicationServiceConfig)
2016-06-06 11:35:58,372 INFO DebugSpringConfig:18 - postProcessBeforeInitialization: bean(dataSource)
2016-06-06 11:35:58,490 INFO DebugSpringConfig:18 - postProcessBeforeInitialization: bean(org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration$DataSourceInitializerConfiguration)
2016-06-06 11:36:00,890 INFO DebugSpringConfig:18 - postProcessBeforeInitialization: bean(spring.datasource.CONFIGURATION_PROPERTIES)
2016-06-06 11:36:00,941 INFO DebugSpringConfig:18 - postProcessBeforeInitialization: bean(dataSourceInitializer)
2016-06-06 11:36:04,189 INFO DebugSpringConfig:18 - postProcessBeforeInitialization: bean(jpaVendorAdapter)
2016-06-06 11:36:05,630 INFO DebugSpringConfig:18 - postProcessBeforeInitialization: bean(jpaDialect)
2016-06-06 11:36:09,985 INFO DebugSpringConfig:18 - postProcessBeforeInitialization: bean(eclipseLinkProperty)
2016-06-06 11:36:16,705 INFO DebugSpringConfig:18 - postProcessBeforeInitialization: bean(entityManagerFactory)
2016-06-06 11:36:17,817 INFO DebugSpringConfig:18 - postProcessBeforeInitialization: bean(org.springframework.context.event.internalEventListenerProcessor)
2016-06-06 11:36:17,820 INFO DebugSpringConfig:18 - postProcessBeforeInitialization: bean(org.springframework.context.event.internalEventListenerFactory)
2016-06-06 11:36:17,827 INFO DebugSpringConfig:18 - postProcessBeforeInitialization: bean(ApplicationServiceApplication)
2016-06-06 11:36:18,160 INFO DebugSpringConfig:18 - postProcessBeforeInitialization: bean((inner bean)#298a0c11)
2016-06-06 11:36:18,168 INFO DebugSpringConfig:18 - postProcessBeforeInitialization: bean((inner bean)#29c496d3)
2016-06-06 11:36:18,175 INFO DebugSpringConfig:18 - postProcessBeforeInitialization: bean((inner bean)#592e883f)
2016-06-06 11:36:18,201 INFO DebugSpringConfig:18 - postProcessBeforeInitialization: bean((inner bean)#6f672a3f)
2016-06-06 11:36:18,211 INFO DebugSpringConfig:18 - postProcessBeforeInitialization: bean(jpaMappingContext)
当我运行应用程序(没有测试)时,我没有遇到任何异常,以下是记录的步骤 -
2016-06-06 11:49:37,146 INFO DebugSpringConfig:18 - postProcessBeforeInitialization: bean(dataSource)
2016-06-06 11:49:37,152 INFO DebugSpringConfig:18 - postProcessBeforeInitialization: bean(org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration$DataSourceInitializerConfiguration)
2016-06-06 11:49:37,190 INFO DebugSpringConfig:18 - postProcessBeforeInitialization: bean(spring.datasource.CONFIGURATION_PROPERTIES)
2016-06-06 11:49:37,196 INFO DebugSpringConfig:18 - postProcessBeforeInitialization: bean(dataSourceInitializer)
2016-06-06 11:49:37,211 INFO DebugSpringConfig:18 - postProcessBeforeInitialization: bean(jpaVendorAdapter)
2016-06-06 11:49:37,215 INFO DebugSpringConfig:18 - postProcessBeforeInitialization: bean(jpaDialect)
2016-06-06 11:49:37,223 INFO DebugSpringConfig:18 - postProcessBeforeInitialization: bean(eclipseLinkProperty)
2016-06-06 11:49:37,235 INFO DebugSpringConfig:18 - postProcessBeforeInitialization: bean(entityManagerFactory)
2016-06-06 11:49:38,148 INFO DebugSpringConfig:18 - postProcessBeforeInitialization: bean(org.springframework.context.event.internalEventListenerProcessor)
2016-06-06 11:49:38,151 INFO DebugSpringConfig:18 - postProcessBeforeInitialization: bean(org.springframework.context.event.internalEventListenerFactory)
2016-06-06 11:49:38,155 INFO DebugSpringConfig:18 - postProcessBeforeInitialization: bean(ApplicationServiceApplication)
2016-06-06 11:49:38,160 INFO DebugSpringConfig:18 - postProcessBeforeInitialization: bean(swaggerConfig)
2016-06-06 11:49:38,431 INFO DebugSpringConfig:18 - postProcessBeforeInitialization: bean((inner bean)#3b5eab14)
2016-06-06 11:49:38,436 INFO DebugSpringConfig:18 - postProcessBeforeInitialization: bean((inner bean)#1bcbbc70)
2016-06-06 11:49:38,441 INFO DebugSpringConfig:18 - postProcessBeforeInitialization: bean((inner bean)#2f7fd8d2)
2016-06-06 11:49:38,471 INFO DebugSpringConfig:18 - postProcessBeforeInitialization: bean((inner bean)#7d7e1cb4)
2016-06-06 11:49:38,480 INFO DebugSpringConfig:18 - postProcessBeforeInitialization: bean(jpaMappingContext)
2016-06-06 11:49:38,534 INFO DebugSpringConfig:18 - postProcessBeforeInitialization: bean(ApplicationRepository)
2016-06-06 11:49:39,116 INFO DebugSpringConfig:18 - postProcessBeforeInitialization: bean(ApplicationServiceImpl)
2016-06-06 11:49:39,128 INFO DebugSpringConfig:18 - postProcessBeforeInitialization: bean(referrerMappingController)
答案 0 :(得分:1)
进一步调查下面的堆栈跟踪的具体部分:
Caused by: java.lang.NoSuchMethodError: javax.persistence.EntityManagerFactory.getMetamodel()Ljavax/persistence/metamodel/Metamodel;
at org.springframework.data.jpa.repository.config.JpaMetamodelMappingContextFactoryBean.getMetamodels(JpaMetamodelMappingContextFactoryBean.java:90)
at org.springframework.data.jpa.repository.config.JpaMetamodelMappingContextFactoryBean.createInstance(JpaMetamodelMappingContextFactoryBean.java:56)
at org.springframework.data.jpa.repository.config.JpaMetamodelMappingContextFactoryBean.createInstance(JpaMetamodelMappingContextFactoryBean.java:26)
我发现JpaMetamodelMappingContextFactoryBean.java指的是错误引用的旧版javax.persistence库。
我从maven中取出了上面的lib,并将这个lib的依赖项与org.eclipse.persistence库对齐。这个实现了EntityManagerFactory,实现了getMetamodel()方法。
因此问题得到了解决。
答案 1 :(得分:0)
我有两个具有不同版本(1和2)的javax.persistence库,它们是从依赖项jars(EclipseLink:2.5.2,其中包括(javax.persistence:2.1.0)和persistence-api:1.0.2)导入的。我需要做的就是将EclipseLink移到pom.xml中具有persistence-api:1.0.2的项目之前,依赖顺序很重要,这在document中进行了定义:从Maven 2.0.9开始,这就是顺序在重要的声明中:第一个声明获胜。