繁体   English   中英

找不到 Spring Boot 2.1 EntityManagerFactory Bean

[英]Spring Boot 2.1 EntityManagerFactory Bean could not be found

我有一个带有 JPA、Web 和 PostgreSQL 的简单 Spring Boot 项目。 我正在使用最新的 Spring Boot 版本2.1.3.RELEASE

添加简单的 JpaRepository 应用程序在启动时失败并出现以下错误:

***************************
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;
}

和 JpaRepository:

public interface SimpleJpaRepository extends JpaRepository<SimpleEntity, Long> {}

这是我的 application.yml:

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

如果我将spring-boot-starter-parent更改为2.0.8.RELEASE应用程序将正确启动。

好的,最后问题是安迪威尔金森所说的缓存 Hibernate 依赖项。

从我的 M2 存储库中删除org.hibernate文件夹并更新 maven 项目后,它可以正常工作。

我正在使用最新的 Spring Boot 版本 2.1.2.RELEASE。
但是错误地,在属性标签中,我忘记删除 4.3.5 版本,如下所示,这会导致加载的库之间产生混淆。
<properties><hibernate.version>4.3.5.Final</hibernate.version></properties>
在 org.hibernate 文件夹的 .m2 存储库中,我下载了两个版本库。 删除 org.hibernate 文件夹并更新 maven 项目。 它会运行。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM