找不到 Spring Boot 2.1 EntityManagerFactory Bean

我有一个简单的带有 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应用程序将正确启动。


眼眸繁星
浏览 286回答 2
2回答

千巷猫影

好的,所以最后问题出在Andy Wilkinson所说的缓存 Hibernate 依赖项上。从我的 M2 存储库中删除org.hibernate文件夹并更新 maven 项目后,它可以正常工作。

POPMUISE

我正在使用最新的 Spring Boot 版本 2.1.2.RELEASE。但是错误地,在属性标签中我忘记删除 4.3.5 版本,如下所示,这会导致加载的库之间出现混淆。&nbsp;在 org.hibernate 文件夹的 .m2 存储库中,我下载了两个版本库。删除 org.hibernate 文件夹并更新 maven 项目。它会运行。<properties><hibernate.version>4.3.5.Final</hibernate.version></properties>
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java