title: Java Spring Boot: Consider defining a bean named 'entityManagerFactory' in your configuration
body: <p>I'm working on a basic application using Java Spring Boot, I'm stuck on this error:</p>
  <p>This is the error message:</p>
  <pre><code>Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
  2021-12-16 12:44:40.321 ERROR 5698 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 
  ***************************
  APPLICATION FAILED TO START
  ***************************
  Description:
  Field userRepository in com.htamayo.sbcrashcourse.SbcrashcourseApplication 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.
  </code></pre>
  <ol>
  <li><p>My main class looks like this:</p>
  <pre><code> package com.htamayo.sbcrashcourse;
  
   import com.htamayo.sbcrashcourse.lendingengine.domain.model.User;
   import com.htamayo.sbcrashcourse.lendingengine.domain.repository.UserRepository;
   import org.springframework.beans.factory.annotation.Autowired;
   import org.springframework.boot.CommandLineRunner;
   import org.springframework.boot.SpringApplication;
   import org.springframework.boot.autoconfigure.SpringBootApplication;
   import org.springframework.context.annotation.Bean;
   import org.springframework.context.annotation.ComponentScan;
   import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
  
   @SpringBootApplication
   @ComponentScan(basePackages = {&quot;com.htamayo.sbcrashcourse.lendingengine&quot;})
   @EnableJpaRepositories(&quot;com.htamayo.sbcrashcourse.lendingengine.domain.repository&quot;)
   public class SbcrashcourseApplication implements CommandLineRunner {
  
   @Autowired
   private UserRepository userRepository;
  
   public static void main(String[] args) {SpringApplication.run(SbcrashcourseApplication.class, args);}
  
   @Override
   public void run(String... args) throws Exception {
       userRepository.save(new User(1, &quot;John&quot;, &quot;B&quot;, 27, &quot;Software Developer&quot;));
       userRepository.save(new User(2, &quot;Peter&quot;, &quot;C&quot;, 21, &quot;Pilot&quot;));
       userRepository.save(new User(3, &quot;Henry&quot;, &quot;E&quot;, 21, &quot;Unemployed&quot;));
   }
  </code></pre>
  <p>}</p>
  </li>
  <li><p>UserRepository class is this:</p>
  <pre><code>package com.htamayo.sbcrashcourse.lendingengine.domain.repository;
  
   import com.htamayo.sbcrashcourse.lendingengine.domain.model.User;
   import org.springframework.data.jpa.repository.JpaRepository;
  
   public interface UserRepository extends JpaRepository&lt;User, Long&gt; {
  
   }
  </code></pre>
  </li>
  <li><p>And my pom.xml looks like this:</p>
  <pre><code> &lt;dependencies&gt;
   &lt;dependency&gt;
       &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
       &lt;artifactId&gt;spring-boot-starter-actuator&lt;/artifactId&gt;
   &lt;/dependency&gt;
   &lt;dependency&gt;
       &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
       &lt;artifactId&gt;spring-boot-starter-data-jpa&lt;/artifactId&gt;
   &lt;/dependency&gt;
   &lt;dependency&gt;
       &lt;groupId&gt;org.springframework&lt;/groupId&gt;
       &lt;artifactId&gt;spring-orm&lt;/artifactId&gt;
   &lt;/dependency&gt;
   &lt;dependency&gt;
       &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
       &lt;artifactId&gt;hibernate-core&lt;/artifactId&gt;
       &lt;version&gt;5.4.32.Final&lt;/version&gt;
   &lt;/dependency&gt;
   &lt;dependency&gt;
       &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
       &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
   &lt;/dependency&gt;
   &lt;dependency&gt;
       &lt;groupId&gt;mysql&lt;/groupId&gt;
       &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
       &lt;scope&gt;runtime&lt;/scope&gt;
   &lt;/dependency&gt;
   &lt;dependency&gt;
       &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
       &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
       &lt;scope&gt;test&lt;/scope&gt;
   &lt;/dependency&gt;
   &lt;dependency&gt;
       &lt;groupId&gt;org.springframework&lt;/groupId&gt;
       &lt;artifactId&gt;spring-web&lt;/artifactId&gt;
       &lt;version&gt;5.3.9&lt;/version&gt;
   &lt;/dependency&gt;
   &lt;dependency&gt;
       &lt;groupId&gt;org.springframework&lt;/groupId&gt;
       &lt;artifactId&gt;spring-webmvc&lt;/artifactId&gt;
       &lt;version&gt;5.3.9&lt;/version&gt;
   &lt;/dependency&gt;
   &lt;dependency&gt;
       &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
       &lt;artifactId&gt;hibernate-core&lt;/artifactId&gt;
       &lt;version&gt;5.5.7.Final&lt;/version&gt;
   &lt;/dependency&gt;
   &lt;dependency&gt;
       &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
       &lt;artifactId&gt;hibernate-entitymanager&lt;/artifactId&gt;
       &lt;version&gt;5.5.7.Final&lt;/version&gt;
   &lt;/dependency&gt;
   &lt;dependency&gt;
       &lt;groupId&gt;javax.xml.bind&lt;/groupId&gt;
       &lt;artifactId&gt;jaxb-api&lt;/artifactId&gt;
       &lt;version&gt;2.3.1&lt;/version&gt;
   &lt;/dependency&gt;
  </code></pre>
   
   
       
           
               org.springframework.boot
                 spring-boot-maven-plugin
           
       
   
  </li>
  </ol>
  
  <p>I've been searching for solutions on Google but so far nothing, so my question is: I don't understand how to overcome the EntityManagerFactory error, am I missing a dependency? or should I refactor my code? any solutions?</p>
  <p>Thanks a lot for your suggestions.</p>