Java 找不到Spring Boot 2.1 EntityManagerFactory Bean
我有一个简单的SpringBoot项目,包括JPA、Web和PostgreSQL。我使用的是最新的Spring Boot版本2.1.3.RELEASE 添加简单JpaRepository后,应用程序在启动时失败,出现以下错误:Java 找不到Spring Boot 2.1 EntityManagerFactory Bean,java,spring,spring-boot,spring-data-jpa,Java,Spring,Spring Boot,Spring Data Jpa,我有一个简单的SpringBoot项目,包括JPA、Web和PostgreSQL。我使用的是最新的Spring Boot版本2.1.3.RELEASE 添加简单JpaRepository后,应用程序在启动时失败,出现以下错误: *************************** APPLICATION FAILED TO START *************************** Description: Field dataMappingRepository in com.my
***************************
APPLICATION FAILED TO START
***************************
Description:
Field dataMappingRepository in com.my.example.service.impl.SimpleServiceImpl 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.
我有一个简单的@Service类,如:
public class SimpleServiceImpl implements SimpleService {
@Autowired private SimpleJpaRepository repo;
}
和JPA假设:
public interface SimpleJpaRepository extends JpaRepository<SimpleEntity, Long> {}
如果我将spring boot starter父项更改为2.0.8。释放应用程序将正确启动。好,那么最后问题是缓存的Hibernate依赖项
从我的M2 repo中删除org.hibernate文件夹并更新maven项目后,它工作正常。我使用的是最新的Spring Boot版本2.1.2.RELEASE。
但错误的是,在properties标签中,我忘了删除4.3.5版本,如下所示,这会导致加载的库之间的混淆。
4.3.5.最终版
在org.hibernate文件夹的.m2存储库中,我下载了两个版本库。
删除org.hibernate文件夹并更新maven项目。它将运行。听起来好像Hibernate尚未自动配置。Spring Boot 2.0.8和2.1.3使用不同版本的Hibernate(分别为5.2.17.Final和5.3.7.Final),5.3.7.Final的一个JAR在下载时可能已损坏。尝试从生成系统的缓存中删除Hibernate,然后再次生成应用程序。能否显示pom.xml?选中此复选框是否已启用@ComponentScan
spring:
datasource:
url: jdbc:postgresql://localhost:5432/simple
username: user
password: pass
driver-class-name: org.postgresql.Driver
jpa:
show-sql: false
properties:
hibernate:
dialect: org.hibernate.dialect.PostgreSQLDialect
hibernate:
ddl-auto: validate