为了账号安全,请及时绑定邮箱和手机立即绑定

找不到 Spring Boot 2.1 EntityManagerFactory Bean

找不到 Spring Boot 2.1 EntityManagerFactory Bean

眼眸繁星 2022-06-30 19:00:42
我有一个简单的带有 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应用程序将正确启动。
查看完整描述

2 回答

?
千巷猫影

TA贡献1829条经验 获得超7个赞

好的,所以最后问题出在Andy Wilkinson所说的缓存 Hibernate 依赖项上。

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


查看完整回答
反对 回复 2022-06-30
?
POPMUISE

TA贡献1765条经验 获得超5个赞

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

查看完整回答
反对 回复 2022-06-30
  • 2 回答
  • 0 关注
  • 284 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号