我有一個(gè)簡(jiǎn)單的帶有 JPA、Web 和 PostgreSQL 的 Spring Boot 項(xiàng)目。我正在使用最新的 Spring Boot 版本2.1.3.RELEASE。添加簡(jiǎn)單的 JpaRepository 應(yīng)用程序后啟動(dòng)失敗并出現(xiàn)以下錯(cuò)誤:***************************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.我有一個(gè)簡(jiǎn)單的@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應(yīng)用程序?qū)⒄_啟動(dòng)。
2 回答

千巷貓影
TA貢獻(xiàn)1829條經(jīng)驗(yàn) 獲得超7個(gè)贊
好的,所以最后問(wèn)題出在Andy Wilkinson所說(shuō)的緩存 Hibernate 依賴項(xiàng)上。
從我的 M2 存儲(chǔ)庫(kù)中刪除org.hibernate文件夾并更新 maven 項(xiàng)目后,它可以正常工作。

POPMUISE
TA貢獻(xiàn)1765條經(jīng)驗(yàn) 獲得超5個(gè)贊
我正在使用最新的 Spring Boot 版本 2.1.2.RELEASE。
但是錯(cuò)誤地,在屬性標(biāo)簽中我忘記刪除 4.3.5 版本,如下所示,這會(huì)導(dǎo)致加載的庫(kù)之間出現(xiàn)混淆。 在 org.hibernate 文件夾的 .m2 存儲(chǔ)庫(kù)中,我下載了兩個(gè)版本庫(kù)。刪除 org.hibernate 文件夾并更新 maven 項(xiàng)目。它會(huì)運(yùn)行。<properties><hibernate.version>4.3.5.Final</hibernate.version></properties>
添加回答
舉報(bào)
0/150
提交
取消