标签:spring maven maven-3 spring-boot-2 spring-data-jpa
我正在批处理,我遇到了一个问题.我已经确定了我的问题的原因,但我无法解决它.
一旦我在我的pom中添加依赖项,我就会开始出错
maven依赖是
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
</dependency>
我的pom如下所示
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.edf.fr.batch</groupId>
<artifactId>edf-batch</artifactId>
<version>0.0.1-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.6.RELEASE</version>
</parent>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-batch</artifactId>
</dependency>
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
</dependency>
<dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.1-901-1.jdbc4</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
我得到的错误是这个
java.lang.NoClassDefFoundError: javax/persistence/EntityManagerFactory
at
org.springframework.data.jpa.util.BeanDefinitionUtils.(BeanDefinitionUtils.java:53)
~[spring-data-jpa-1.11.6.RELEASE.jar:na] at
org.springframework.data.jpa.repository.support.EntityManagerBeanDefinitionRegistrarPostProcessor.postProcessBeanFactory(EntityManagerBeanDefinitionRegistrarPostProcessor.java:54)
~[spring-data-jpa-1.11.6.RELEASE.jar:na] at
org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:281)
~[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE] at
org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:176)
~[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE] at
org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:687)
~[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE] at
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:525)
~[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE] at
org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693)
[spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE] at
org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360)
[spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE] at
org.springframework.boot.SpringApplication.run(SpringApplication.java:303)
[spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE] at
org.springframework.boot.SpringApplication.run(SpringApplication.java:1118)
[spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE] at
org.springframework.boot.SpringApplication.run(SpringApplication.java:1107)
[spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE] at
com.edf.fr.batch.MarcheBatchApplication.main(MarcheBatchApplication.java:10)
[classes/:na] Caused by: java.lang.ClassNotFoundException:
javax.persistence.EntityManagerFactory at
java.net.URLClassLoader.findClass(URLClassLoader.java:381)
~[na:1.8.0_60] at
java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_60]
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
~[na:1.8.0_60] at
java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_60]
… 12 common frames omitted2017-08-14 16:18:43.676 INFO 11676 — [ main]
s.c.a.AnnotationConfigApplicationContext : Closing
org.springframework.context.annotation.AnnotationConfigApplicationContext@48a242ce:
startup date [Mon Aug 14 16:18:42 CEST 2017]; root of context
hierarchy 2017-08-14 16:18:43.677 WARN 11676 — [ main]
s.c.a.AnnotationConfigApplicationContext : Exception thrown from
LifecycleProcessor on context closejava.lang.IllegalStateException: LifecycleProcessor not initialized –
call ‘refresh’ before invoking lifecycle methods via the context:
org.springframework.context.annotation.AnnotationConfigApplicationContext@48a242ce:
startup date [Mon Aug 14 16:18:42 CEST 2017]; root of context
hierarchy at
org.springframework.context.support.AbstractApplicationContext.getLifecycleProcessor(AbstractApplicationContext.java:427)
[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE] at
org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:999)
[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE] at
org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:958)
[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE] at
org.springframework.boot.SpringApplication.handleRunFailure(SpringApplication.java:750)
[spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE] at
org.springframework.boot.SpringApplication.run(SpringApplication.java:314)
[spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE] at
org.springframework.boot.SpringApplication.run(SpringApplication.java:1118)
[spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE] at
org.springframework.boot.SpringApplication.run(SpringApplication.java:1107)
[spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE] at
com.edf.fr.batch.MarcheBatchApplication.main(MarcheBatchApplication.java:10)
[classes/:na]2017-08-14 16:18:43.678 ERROR 11676 — [ main]
o.s.b.f.s.DefaultListableBeanFactory : Destroy method on bean with
name
‘org.springframework.boot.autoconfigure.internalCachingMetadataReaderFactory’
threw an exceptionjava.lang.IllegalStateException: ApplicationEventMulticaster not
initialized – call ‘refresh’ before multicasting events via the
context:
org.springframework.context.annotation.AnnotationConfigApplicationContext@48a242ce:
startup date [Mon Aug 14 16:18:42 CEST 2017]; root of context
hierarchy at
org.springframework.context.support.AbstractApplicationContext.getApplicationEventMulticaster(AbstractApplicationContext.java:414)
[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE] at
org.springframework.context.support.ApplicationListenerDetector.postProcessBeforeDestruction(ApplicationListenerDetector.java:97)
~[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE] at
org.springframework.beans.factory.support.DisposableBeanAdapter.destroy(DisposableBeanAdapter.java:253)
~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE] at
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroyBean(DefaultSingletonBeanRegistry.java:578)
[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE] at
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingleton(DefaultSingletonBeanRegistry.java:554)
[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE] at
org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingleton(DefaultListableBeanFactory.java:961)
[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE] at
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingletons(DefaultSingletonBeanRegistry.java:523)
[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE] at
org.springframework.beans.factory.support.FactoryBeanRegistrySupport.destroySingletons(FactoryBeanRegistrySupport.java:230)
[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE] at
org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingletons(DefaultListableBeanFactory.java:968)
[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE] at
org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:1030)
[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE] at
org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:1006)
[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE] at
org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:958)
[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE] at
org.springframework.boot.SpringApplication.handleRunFailure(SpringApplication.java:750)
[spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE] at
org.springframework.boot.SpringApplication.run(SpringApplication.java:314)
[spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE] at
org.springframework.boot.SpringApplication.run(SpringApplication.java:1118)
[spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE] at
org.springframework.boot.SpringApplication.run(SpringApplication.java:1107)
[spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE] at
com.edf.fr.batch.MarcheBatchApplication.main(MarcheBatchApplication.java:10)
[classes/:na]
解决方法:
从给定的堆栈跟踪中你可以看到找不到某些类,因为你使用的是spring引导,spring引用使用包含多个依赖项的meta依赖项,如spring-boot-cookbook中所述
Spring Boot aims to simplify the process of getting started with an application creation.
Spring Boot starters are bootstrap libraries that contain a collection of all the relevant
transitive dependencies that are needed to start a particular functionality
spring-data-jpa是不够的,还有一些你需要的依赖,使用spring-boot-starter-data-jpa
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
标签:spring,maven,maven-3,spring-boot-2,spring-data-jpa 来源: https://codeday.me/bug/20190608/1196307.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。