Error: "Spring Boot: Consider defining a bean named 'entityManagerFactory' in your configuration"

Warning Message:

When working with Spring Boot, you might encounter the following warning message: Consider defining a bean named 'entityManagerFactory' in your configuration.

This warning suggests that an entity manager factory bean is not defined in your application configuration.

To resolve this warning, you can take the following steps:

  1. Define an entity manager factory bean in your Spring Boot configuration. You can do this by creating a method annotated with @Bean that returns an EntityManagerFactory instance.
  2. If you're using JPA, make sure you have configured the necessary properties for the entity manager factory, such as data source configuration and JPA vendor properties.
  3. Ensure that your application's configuration is properly scanned by Spring Boot and that the bean definition is picked up during application startup.
  4. If you're using Spring Boot auto-configuration, make sure that your application dependencies and configurations are compatible with the default auto-configuration provided by Spring Boot.
  5. After defining the entity manager factory bean, restart your Spring Boot application to apply the changes and verify that the warning message no longer appears.

I encountered the exact same issue. Upon checking the Maven build log, I discovered an error related to hibernate packages, specifically complaining about "invalid LOC header (bad signature)." To resolve this, I deleted the subdirectories under .m2\repository\org\hibernate\hibernate-core and then recompiled my project.

In my case, the issue stemmed from missing the Hibernate Entity Manager dependency:


Initially, I only had the Hibernate Core dependency:


To further resolve the issue, I added the following dependency:


In Spring Boot, there's no need to annotate your repository class with @Repository. Simply extend JpaRepository on your interface, and Spring Boot will handle the rest. For example:

public interface YourRepository extends JpaRepository<YourDomain, Serializable> {
    YourDomain findBySomeParameter(Long parameter);

You also don't need to add these annotations:

  • @EnableJpaRepositories
  • @EntityScan
  • @ComponentScan

Spring Boot handles these automatically, unless you're performing custom configuration.

I encountered a similar issue when I started learning Spring Boot a few months ago. I'm not sure if Spring takes directory structure seriously. My directory structure was similar to @Pawan's. The solution was to move the repository folder one level up, i.e., into the parent "abc" folder. Then, annotate your DeviceDao class with @Service. Finally, update the repository path in @EnableJpaRepository. This approach worked for me. I hope this helps!

The issue I encountered was related to the properties file. For some reason, I had included this line (although I can't recall why):


I simply commented out this line, and the problem was resolved.