我在我的 springboot 项目中使用 spring boot jpa 来访问和管理数据库。在我拥有 springboot 版本 2.3 和 java 8 之前,它工作正常,但自从我迁移到 springboot 3.0.6 和 java 17 后,它开始给出这个 EntityManagerFactory 类未找到错误。理想情况下,springboot data jpa 应该有这个类,但不知何故,即使我为 jpa 指定了最新版本,它也在那里。我发现了一个类似的线程 Fresh Springboot project won't start Caused by: java.lang.ClassNotFoundException: javax.persistence.EntityManagerFactory ,我尝试了指定的解决方案来清除本地存储库并删除 mt 文件夹并重新下载依赖项但问题仍然存在。
如果我包含 javax.persistence-api 它会给出以下错误
有谁知道可能出了什么问题。
我正在使用这些 jpa 相关的依赖项:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
这些是在 main 和 test application.yml 中定义的道具
## AWS-RDS Postgresql config
spring.datasource.url: jdbc:postgresql://localhost:5432/mytestdb
spring.jpa.properties.hibernate.default_schema: public
spring.datasource.username: postgres
spring.datasource.password: mysecretpassword
#JPA
#spring.jpa.database-platform: org.hibernate.dialect.PostgreSQLDialect
spring.jpa.properties.hibernate.dialect: org.hibernate.dialect.PostgreSQLDialect
spring.data.jpa.repositories.enabled: true
spring.jpa.generate-ddl: true
spring.jpa.hibernate.ddl-auto: update
下面是错误堆栈跟踪
2023-05-15T03:06:14,957 ERROR main boot.SpringApplication:822 - 应用程序运行失败
java.lang.NoClassDefFoundError:javax/persistence/EntityManagerFactory
在 org.springframework.data.jpa.util.BeanDefinitionUtils.(BeanDefinitionUtils.java:56) ~[..%5C..%5C..%5C..%5C..%5CPrakhar.Gupta1%5C.m2% 5Crepository%5Corg%5Cspringframework%5Cdata%5Cspring-data-jpa%5C2.3.4.RELEASE%5Cspring-data-jpa-2.3.4.RELEASE.jar:2.3.4.RELEASE]
在 org.springframework.data.jpa.repository.support.EntityManagerBeanDefinitionRegistrarPostProcessor.postProcessBeanFactory(EntityManagerBeanDefinitionRegistrarPostProcessor.java:71)~[..%5C..%5C..%5C..%5C..%5CPrakhar.Gupta1%5C。 m2%5Crepository%5Corg%5Cspringframework%5Cdata%5Cspring-data-jpa%5C2.3.4.RELEASE%5Cspring-data-jpa-2.3.4.RELEASE.jar:2.3.4.RELEASE]
在 org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:358)~[..%5C..%5C..%5C..%5C..%5CPrakhar.Gupta1%5C.m2%5Crepository% 5Corg%5Cspringframework%5Cspring-context%5C6.0.8%5Cspring-context-6.0.8.jar:6.0.8]
在 org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:194)~[..%5C..%5C..%5C..%5C..%5CPrakhar.Gupta1%5C.m2%5Crepository% 5Corg%5Cspringframework%5Cspring-context%5C6.0.8%5Cspring-context-6.0.8.jar:6.0.8]
在 org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:747)~[..%5C..%5C..%5C..%5C..%5CPrakhar.Gupta1%5C.m2%5Crepository% 5Corg%5Cspringframework%5Cspring-context%5C6.0.8%5Cspring-context-6.0.8.jar:6.0.8]
在 org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:565) ~[..%5C..%5C..%5C..%5C..%5CPrakhar.Gupta1%5C.m2%5Crepository% 5Corg%5Cspringframework%5Cspring-context%5C6.0.8%5Cspring-context-6.0.8.jar:6.0.8]
在 org.springframework.boot.SpringApplication.refresh(SpringApplication.java:732) ~[..%5C..%5C..%5C..%5C..%5CPrakhar.Gupta1%5C.m2%5Crepository%5Corg% 5Cspringframework%5Cboot%5Cspring-boot%5C3.0.6%5Cspring-boot-3.0.6.jar:3.0.6]
在 org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:434) ~[..%5C..%5C..%5C..%5C..%5CPrakhar.Gupta1%5C.m2%5Crepository%5Corg% 5Cspringframework%5Cboot%5Cspring-boot%5C3.0.6%5Cspring-boot-3.0.6.jar:3.0.6]
在 org.springframework.boot.SpringApplication.run(SpringApplication.java:310) ~[..%5C..%5C..%5C..%5C..%5CPrakhar.Gupta1%5C.m2%5Crepository%5Corg% 5Cspringframework%5Cboot%5Cspring-boot%5C3.0.6%5Cspring-boot-3.0.6.jar:3.0.6]
在....
[错误]测试运行:1,失败:0,错误:1,跳过:0,经过的时间:4.391 s<<< FAILURE! - in co.uk.sainsburys.wzoconfigservice.WzoConfigServiceApplicationTests
[ERROR] main Time elapsed: 0.006 s <<< ERROR!
java.lang.NoClassDefFoundError: javax/persistence/EntityManagerFactory
Caused by: java.lang.ClassNotFoundException: javax.persistence.EntityManagerFactory