简体   繁体   中英

Spring Boot 2.1 EntityManagerFactory Bean could not be found

I have simple Spring Boot project with JPA, Web and PostgreSQL. I'm using the latest Spring Boot version 2.1.3.RELEASE .

After adding simple JpaRepository application fails on startup with the following error:

***************************
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.

I have a simple @Service class like:

public class SimpleServiceImpl implements SimpleService {
  @Autowired private SimpleJpaRepository repo;
}

And JpaRepository:

public interface SimpleJpaRepository extends JpaRepository<SimpleEntity, Long> {}

And here is my 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

If I change spring-boot-starter-parent to 2.0.8.RELEASE the application starts correctly.

Ok, so finally the problem was as Andy Wilkinson said with cached Hibernate dependency.

After deleting org.hibernate folder from my M2 repo and updating maven project, it works correctly.

I'm using the latest Spring Boot version 2.1.2.RELEASE.
But mistakenly, in properties tag i forget to delete 4.3.5 version as you see below which cause confusion between library loaded.
<properties><hibernate.version>4.3.5.Final</hibernate.version></properties>
In .m2 repository of org.hibernate folder, i got both version library downloaded. Delete org.hibernate folder and update maven project. It will run.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM