![](/img/trans.png)
[英]Spring-boot: required a bean named 'entityManagerFactory' that could not be found
[英]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.