gpt4 book ai didi

java - 找不到 Spring Boot 2.1 EntityManagerFactory Bean

转载 作者:行者123 更新时间:2023-12-05 05:12:11 25 4
gpt4 key购买 nike

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

最佳答案

好的,最后问题是Andy Wilkinson用缓存的 Hibernate 依赖项说。

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

关于java - 找不到 Spring Boot 2.1 EntityManagerFactory Bean,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54825926/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com