entityManagerFactory bean 未配置休眠 6.0 问题。2.Final 和 spring 引导 2.7.0
entityManagerFactory bean not configured issue with hibernate 6.0.2.Final and spring boot 2.7.0
所以最近我想升级我的 spring 引导项目项目的一些依赖项
特别是这些组件
- jakarat ee 9
- spring 开机 2.7
- 休眠 6.0.2.Final
完成所有更新和代码折射后:更新将 javax 导入到 jakarta,以及一些 hibernate 注释
我从我的本地 .m2 存储库中删除了旧的 hibernate,并且 运行 这个命令 mvn clean install test package
并在 intellij 中启动该项目,但出现以下错误:
16:15:42.410 [Thread-0] DEBUG org.springframework.boot.devtools.restart.classloader.RestartClassLoader - Created RestartClassLoader org.springframework.boot.devtools.restart.classloader.RestartClassLoader@429054cc
. ____ _ __ _ _
/\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.7.0)
2022-05-30 16:15:42.787 INFO 99522 --- [ restartedMain] com.zee.oms.order.Order : Starting Order using Java 17.0.2 on ZL-BLR-MAC170.local with PID 99522 (/Users/manish.prasad/Documents/ZEE-Services/github/zee5-order/target/classes started by manish.prasad in /Users/manish.prasad/Documents/ZEE-Services/github/zee5-order)
2022-05-30 16:15:42.787 DEBUG 99522 --- [ restartedMain] com.zee.oms.order.Order : Running with Spring Boot v2.7.0, Spring v5.3.20
2022-05-30 16:15:42.787 INFO 99522 --- [ restartedMain] com.zee.oms.order.Order : No active profile set, falling back to 1 default profile: "default"
2022-05-30 16:15:42.818 INFO 99522 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2022-05-30 16:15:42.818 INFO 99522 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2022-05-30 16:15:43.347 INFO 99522 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2022-05-30 16:15:43.433 INFO 99522 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 81 ms. Found 4 JPA repository interfaces.
2022-05-30 16:15:43.862 INFO 99522 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2022-05-30 16:15:43.868 INFO 99522 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2022-05-30 16:15:43.868 INFO 99522 --- [ restartedMain] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.63]
2022-05-30 16:15:43.902 INFO 99522 --- [ restartedMain] o.a.c.c.C.[.[localhost].[/order-srv] : Initializing Spring embedded WebApplicationContext
2022-05-30 16:15:43.902 INFO 99522 --- [ restartedMain] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1084 ms
2022-05-30 16:15:44.059 WARN 99522 --- [ restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'orderController': Unsatisfied dependency expressed through field 'orderService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'orderServiceImpl': Unsatisfied dependency expressed through field 'orderRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'orderRepository' defined in com.zee.oms.order.repository.OrderRepository defined in @EnableJpaRepositories declared on JpaRepositoriesRegistrar.EnableJpaRepositoriesConfiguration: Cannot create inner bean '(inner bean)#14203bc' 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)#14203bc': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'entityManagerFactory' available
2022-05-30 16:15:44.061 INFO 99522 --- [ restartedMain] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2022-05-30 16:15:44.072 INFO 99522 --- [ restartedMain] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2022-05-30 16:15:44.080 ERROR 99522 --- [ restartedMain] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Field orderRepository in com.oms.order.service.impl.OrderServiceImpl required a bean named 'entityManagerFactory' that could not be found.
The injection point has the following annotations:
- @org.springframework.beans.factory.annotation.Autowired(required=true)
Action:
Consider defining a bean named 'entityManagerFactory' in your configuration.
Process finished with exit code 0
这是我的 pom:
<?xml version="1.0" encoding="UTF-8"?>
<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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.0</version>
<relativePath/>
</parent>
<groupId>com.zee</groupId>
<artifactId>zee5-order</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>order</name>
<description>Spring Boot project for order-service</description>
<properties>
<java.version>17</java.version>
<hibernate.version>6.0.2.Final</hibernate.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-actuator -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mockito/mockito-all -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.10.19</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>7.0.4.Final</version>
</dependency>
<dependency>
<groupId>jakarta.validation</groupId>
<artifactId>jakarta.validation-api</artifactId>
<version>3.0.2</version>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.6.8</version>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-data-rest</artifactId>
<version>1.6.8</version>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-webmvc-core</artifactId>
<version>1.6.8</version>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-webflux-ui</artifactId>
<version>1.6.8</version>
</dependency>
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
<version>8.5.10</version>
</dependency>
<dependency>
<groupId>com.common-utility</groupId>
<artifactId>common-utility</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-secretsmanager</artifactId>
<version>1.12.220</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>2.1.212</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.vladmihalcea</groupId>
<artifactId>hibernate-types-60</artifactId>
<version>2.16.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
附上添加的依赖项的几个屏幕截图:
spring and spring boot dependencies
jakarta dependencies
任何想法或解决方案,如果有人也升级到此版本并且能够成功 运行 项目。
我也很困惑为什么 javax-persistence 仍然存在并且在 jakarata-persistence 已经 added/there.
时没有被替换
Hibernate 6(以及 Hibernate Validator 7)分别是 Jakarta JPA API 和 Jakarta Validation API 的 JakartaEE 实现。 None 当前 Spring 或 Spring Boot.
支持
计划在今年晚些时候发布的 Spring Framework 6 和 Spring Boot 3 将支持 JakartaEE。
现在继续使用 JavaEE 版本。在你的情况下你需要做两件事
- 删除
hibernate.version
属性
- 将
hibernate-validator
和 jakarta-validation-api
替换为 spring-boot-starter-validation
依赖项。
当您应用这两个修复程序并在今年晚些时候升级到 Spring Boot 3 时,您将获得兼容的正确版本。
所以最近我想升级我的 spring 引导项目项目的一些依赖项 特别是这些组件
- jakarat ee 9
- spring 开机 2.7
- 休眠 6.0.2.Final
完成所有更新和代码折射后:更新将 javax 导入到 jakarta,以及一些 hibernate 注释
我从我的本地 .m2 存储库中删除了旧的 hibernate,并且 运行 这个命令 mvn clean install test package
并在 intellij 中启动该项目,但出现以下错误:
16:15:42.410 [Thread-0] DEBUG org.springframework.boot.devtools.restart.classloader.RestartClassLoader - Created RestartClassLoader org.springframework.boot.devtools.restart.classloader.RestartClassLoader@429054cc
. ____ _ __ _ _
/\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.7.0)
2022-05-30 16:15:42.787 INFO 99522 --- [ restartedMain] com.zee.oms.order.Order : Starting Order using Java 17.0.2 on ZL-BLR-MAC170.local with PID 99522 (/Users/manish.prasad/Documents/ZEE-Services/github/zee5-order/target/classes started by manish.prasad in /Users/manish.prasad/Documents/ZEE-Services/github/zee5-order)
2022-05-30 16:15:42.787 DEBUG 99522 --- [ restartedMain] com.zee.oms.order.Order : Running with Spring Boot v2.7.0, Spring v5.3.20
2022-05-30 16:15:42.787 INFO 99522 --- [ restartedMain] com.zee.oms.order.Order : No active profile set, falling back to 1 default profile: "default"
2022-05-30 16:15:42.818 INFO 99522 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2022-05-30 16:15:42.818 INFO 99522 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2022-05-30 16:15:43.347 INFO 99522 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2022-05-30 16:15:43.433 INFO 99522 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 81 ms. Found 4 JPA repository interfaces.
2022-05-30 16:15:43.862 INFO 99522 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2022-05-30 16:15:43.868 INFO 99522 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2022-05-30 16:15:43.868 INFO 99522 --- [ restartedMain] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.63]
2022-05-30 16:15:43.902 INFO 99522 --- [ restartedMain] o.a.c.c.C.[.[localhost].[/order-srv] : Initializing Spring embedded WebApplicationContext
2022-05-30 16:15:43.902 INFO 99522 --- [ restartedMain] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1084 ms
2022-05-30 16:15:44.059 WARN 99522 --- [ restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'orderController': Unsatisfied dependency expressed through field 'orderService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'orderServiceImpl': Unsatisfied dependency expressed through field 'orderRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'orderRepository' defined in com.zee.oms.order.repository.OrderRepository defined in @EnableJpaRepositories declared on JpaRepositoriesRegistrar.EnableJpaRepositoriesConfiguration: Cannot create inner bean '(inner bean)#14203bc' 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)#14203bc': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'entityManagerFactory' available
2022-05-30 16:15:44.061 INFO 99522 --- [ restartedMain] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2022-05-30 16:15:44.072 INFO 99522 --- [ restartedMain] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2022-05-30 16:15:44.080 ERROR 99522 --- [ restartedMain] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Field orderRepository in com.oms.order.service.impl.OrderServiceImpl required a bean named 'entityManagerFactory' that could not be found.
The injection point has the following annotations:
- @org.springframework.beans.factory.annotation.Autowired(required=true)
Action:
Consider defining a bean named 'entityManagerFactory' in your configuration.
Process finished with exit code 0
这是我的 pom:
<?xml version="1.0" encoding="UTF-8"?>
<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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.0</version>
<relativePath/>
</parent>
<groupId>com.zee</groupId>
<artifactId>zee5-order</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>order</name>
<description>Spring Boot project for order-service</description>
<properties>
<java.version>17</java.version>
<hibernate.version>6.0.2.Final</hibernate.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-actuator -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mockito/mockito-all -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.10.19</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>7.0.4.Final</version>
</dependency>
<dependency>
<groupId>jakarta.validation</groupId>
<artifactId>jakarta.validation-api</artifactId>
<version>3.0.2</version>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.6.8</version>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-data-rest</artifactId>
<version>1.6.8</version>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-webmvc-core</artifactId>
<version>1.6.8</version>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-webflux-ui</artifactId>
<version>1.6.8</version>
</dependency>
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
<version>8.5.10</version>
</dependency>
<dependency>
<groupId>com.common-utility</groupId>
<artifactId>common-utility</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-secretsmanager</artifactId>
<version>1.12.220</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>2.1.212</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.vladmihalcea</groupId>
<artifactId>hibernate-types-60</artifactId>
<version>2.16.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
附上添加的依赖项的几个屏幕截图:
spring and spring boot dependencies
jakarta dependencies
任何想法或解决方案,如果有人也升级到此版本并且能够成功 运行 项目。 我也很困惑为什么 javax-persistence 仍然存在并且在 jakarata-persistence 已经 added/there.
时没有被替换Hibernate 6(以及 Hibernate Validator 7)分别是 Jakarta JPA API 和 Jakarta Validation API 的 JakartaEE 实现。 None 当前 Spring 或 Spring Boot.
支持计划在今年晚些时候发布的 Spring Framework 6 和 Spring Boot 3 将支持 JakartaEE。
现在继续使用 JavaEE 版本。在你的情况下你需要做两件事
- 删除
hibernate.version
属性 - 将
hibernate-validator
和jakarta-validation-api
替换为spring-boot-starter-validation
依赖项。
当您应用这两个修复程序并在今年晚些时候升级到 Spring Boot 3 时,您将获得兼容的正确版本。