title: Spring boot (mysql with jpa ): No bean named 'entityManagerFactory' available
body: <p>Started building a(<em>first</em>) spring boot application and this is my spring boot main class (<a href="https://github.com/sureshatta/stackOverflowExamples/tree/master/SpringBoot/MySQL" rel="noreferrer">Full code on github</a>)</p>
  
  <pre><code>@EnableAutoConfiguration
  @SpringBootApplication
  public class Application {
  
      public static void main(String[] args) {
          SpringApplication.run(Application.class, args);
      }
  }
  </code></pre>
  
  <p>And here is the pom.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
      &lt;groupId&gt;com.example&lt;/groupId&gt;
      &lt;artifactId&gt;demo&lt;/artifactId&gt;
      &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
      &lt;packaging&gt;jar&lt;/packaging&gt;
  
      &lt;name&gt;demo&lt;/name&gt;
      &lt;description&gt;Demo project for Spring Boot&lt;/description&gt;
  
      &lt;parent&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
          &lt;version&gt;1.5.6.RELEASE&lt;/version&gt;
          &lt;relativePath/&gt; &lt;!-- lookup parent from repository --&gt;
      &lt;/parent&gt;
  
      &lt;properties&gt;
          &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
          &lt;project.reporting.outputEncoding&gt;UTF-8&lt;/project.reporting.outputEncoding&gt;
          &lt;java.version&gt;1.8&lt;/java.version&gt;
      &lt;/properties&gt;
  
      &lt;dependencies&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.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-jersey&lt;/artifactId&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;/dependencies&gt;
  
      &lt;build&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
  
  
  &lt;/project&gt;
  </code></pre>
  
  <p>I am keep getting the below error. What I am missing to add? Why I need to add a bean  bean named 'entityManagerFactory' ?? and is it necessary even after using spring boot ??</p>
  
  <p>My repo looks like this if that matter </p>
  
  <pre><code>public interface RegistrationRepo extends JpaRepository&lt;User, Long&gt; {
       User findByEmail(String email); 
  }  
  </code></pre>
  
  <blockquote>
    <p>.   ____          _            __ _ _
    /\ / <strong><em>'</em> __ _ <em>(</em>)_ __  __ _ \ \ \ \
    ( ( )_</strong> | '_ | '<em>| | '</em> / <em>` | \ \ \ \
    \/  <strong></em>)| |<em>)| | | | | || (</em>| |  ) ) ) )
     '  |____| .</strong>|<em>| |</em>|<em>| |</em>__, | / / / /
    =========|_|==============|___/=/<em>/</em>/_/
    :: Spring Boot ::        (v1.5.6.RELEASE)</p>
    
    <p>2017-09-13 12:48:38.808  INFO 15361 --- [           main] com.rightlink.RightLinkApplication       : Starting RightLinkApplication on Admins-MacBook-Pro.local with PID 15361 (/Users/sureshatta/Documents/workspace-sts-3.9.0.RELEASE/RightLink/target/classes started by sureshatta in /Users/sureshatta/Documents/workspace-sts-3.9.0.RELEASE/RightLink)
    2017-09-13 12:48:38.811  INFO 15361 --- [           main] com.rightlink.RightLinkApplication       : No active profile set, falling back to default profiles: default
    2017-09-13 12:48:38.865  INFO 15361 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@120d6fe6: startup date [Wed Sep 13 12:48:38 IST 2017]; root of context hierarchy
    2017-09-13 12:48:40.380  INFO 15361 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8181 (http)
    2017-09-13 12:48:40.402  INFO 15361 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
    2017-09-13 12:48:40.403  INFO 15361 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.16
    2017-09-13 12:48:40.566  INFO 15361 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
    2017-09-13 12:48:40.567  INFO 15361 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1705 ms
    2017-09-13 12:48:40.743  INFO 15361 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Mapping servlet: 'dispatcherServlet' to [/]
    2017-09-13 12:48:40.752  INFO 15361 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/<em>]
    2017-09-13 12:48:40.753  INFO 15361 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/</em>]
    2017-09-13 12:48:40.753  INFO 15361 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'httpPutFormContentFilter' to: [/<em>]
    2017-09-13 12:48:40.753  INFO 15361 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/</em>]
    2017-09-13 12:48:40.844  WARN 15361 --- [           main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'registerController': Unsatisfied dependency expressed through field 'regServices'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'regService': Unsatisfied dependency expressed through field 'registrationRepo'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'registrationRepo': Cannot create inner bean '(inner bean)#43c67247' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property 'entityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#43c67247': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'entityManagerFactory' available
    2017-09-13 12:48:40.849  INFO 15361 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
    2017-09-13 12:48:40.903  INFO 15361 --- [           main] utoConfigurationReportLoggingInitializer : </p>
    
    <p>Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
    2017-09-13 12:48:40.975 ERROR 15361 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : </p>
    
    <hr>
    
    <p>APPLICATION FAILED TO START</p>
    
    <hr>
    
    <p>Description:</p>
    
    <p>Field registrationRepo in com.rightlink.services.RegistrationService required a bean named 'entityManagerFactory' that could not be found.</p>
    
    <p>Action:</p>
    
    <p>Consider defining a bean named 'entityManagerFactory' in your configuration.</p>
  </blockquote>
  
  <p>application.properties</p>
  
  <pre><code>spring.datasource.url=jdbc:mysql://localhost:3306/Test
  spring.datasource.username=root
  spring.datasource.password=root
  spring.datasource.driver-class-name=com.mysql.jdbc.Driver
  spring.jpa.hibernate.ddl-auto=update
  server.port=8181
  </code></pre>
  
  <p>Tried adding <code>@Repository</code> annotation for repo, and also added <code>@enableJpaRepositories</code> annotation in main class. Nothing helps. </p>