3

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.

MPhil
  • 881
  • 1
  • 12
  • 24
Danny
  • 682
  • 1
  • 11
  • 21
  • 5
    It sounds like Hibernate hasn't been auto-configured. Spring Boot 2.0.8 and 2.1.3 use different versions of Hibernate (5.2.17.Final and 5.3.7.Final respectively) and it's possible that one of the jars for 5.3.7.Final was corrupted when it was downloaded. Try deleting Hibernate from your build system's cache and building your application again. – Andy Wilkinson Feb 22 '19 at 12:52
  • Can you show your pom.xml? – Simon Martinelli Feb 22 '19 at 16:59
  • https://stackoverflow.com/questions/24520602/spring-data-jpa-no-bean-named-entitymanagerfactory-is-defined-injection-of-a check this – Vyshnav Ramesh Thrissur Feb 22 '19 at 17:17
  • Have you enabled @ComponentScan – Santosh b Feb 25 '19 at 11:58

2 Answers2

2

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.

Danny
  • 682
  • 1
  • 11
  • 21
0

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.