title: Spring Boot MySQL REST Error - Required a bean named 'entityManagerFactory'/'emf' that could not be found
body: <p>I am trying to create a very simple REST service using Spring Boot MySQL. But unable to get the around the error. I have done a lot of searches and most results told me that the below code is enough to build a bare-bones REST service that can perform CRUD operation.</p>
  
  <p>I keep getting the error </p>
  
  <pre><code>***************************
  APPLICATION FAILED TO START
  ***************************
  Description:
  Field repo in org.bluedolphin.spring.data.mysql.ActorController required a bean named 'entityManagerFactory' that could not be found.
  Action:
  Consider defining a bean named 'entityManagerFactory' in your configuration.
  </code></pre>
  
  <p>And once i add the line </p>
  
  <pre><code>@EnableJpaRepositories(basePackages="org.bluedolphin.spring.data.mysql", entityManagerFactoryRef="emf")
  </code></pre>
  
  <p>in the file SpringDataMysqlApplication, I start getting the following error</p>
  
  <pre><code>***************************
  APPLICATION FAILED TO START
  ***************************
  Description:
  Field repo in org.bluedolphin.spring.data.mysql.ActorController required a bean named 'emf' that could not be found.
  Action:
  Consider defining a bean named 'emf' in your configuration.
  </code></pre>
  
  <p>The entire code is as below.</p>
  
  <p>application.properties</p>
  
  <pre><code>#Server details
  server.port=8180
  # Replace with your connection string
  spring.datasource.url=jdbc:mysql://localhost:3307/sakila
  # Replace with your credentials
  spring.datasource.username=root
  spring.datasource.password=password
  spring.datasource.driverClassName=com.mysql.jdbc.Driver
  </code></pre>
  
  <p>SpringDataMysqlApplication</p>
  
  <pre><code>@SpringBootApplication
  @EnableJpaRepositories(basePackages="org.bluedolphin.spring.data.mysql", entityManagerFactoryRef="emf")
  public class SpringDataMysqlApplication {
  
      private static final Logger log = LoggerFactory.getLogger(SpringDataMysqlApplication.class);
  
      public static void main(String[] args) {
          SpringApplication.run(SpringDataMysqlApplication.class, args);
      }
  }
  </code></pre>
  
  <p>Actor</p>
  
  <pre><code>@Entity
  @Table(name = "actor")
  public class Actor {
  
      @Id
      @GeneratedValue(strategy=GenerationType.AUTO)
      private long id;
      private String first_name;
      private String last_name;
      private Date last_update;
  
      public Actor(int id, String first_name, String last_name, Date last_update) {
          super();
          this.id = id;
          this.first_name = first_name;
          this.last_name = last_name;
          this.last_update = last_update;
      }
  
      public Actor() {
          super();
      }
  
  
      public long getId() {
          return id;
      }
  
      public void setId(long id) {
          this.id = id;
      }
  
      public String getFirst_name() {
          return first_name;
      }
  
      public void setFirst_name(String first_name) {
          this.first_name = first_name;
      }
  
      public String getLast_name() {
          return last_name;
      }
  
      public void setLast_name(String last_name) {
          this.last_name = last_name;
      }
  
      public Date getLast_update() {
          return last_update;
      }
  
      public void setLast_update(Date last_update) {
          this.last_update = last_update;
      }
  
      @Override
      public String toString() {
          return "Actor [id=" + id + ", first_name=" + first_name + ", last_name=" + last_name + ", last_update="
                  + last_update + "]";
      }
  }
  </code></pre>
  
  <p>ActorRepository</p>
  
  <pre><code>public interface ActorRepository extends CrudRepository&lt;Actor, Long&gt; {
  
  }
  </code></pre>
  
  <p>POM</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;org.bluedolphin.spring.data.mysql&lt;/groupId&gt;
      &lt;artifactId&gt;spring-data-mysql&lt;/artifactId&gt;
      &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
      &lt;packaging&gt;jar&lt;/packaging&gt;
      &lt;name&gt;spring-data-mysql&lt;/name&gt;
      &lt;description&gt;spring-data-mysql&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;2.0.0.BUILD-SNAPSHOT&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-thymeleaf&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;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;repositories&gt;
          &lt;repository&gt;
              &lt;id&gt;spring-snapshots&lt;/id&gt;
              &lt;name&gt;Spring Snapshots&lt;/name&gt;
              &lt;url&gt;https://repo.spring.io/snapshot&lt;/url&gt;
              &lt;snapshots&gt;
                  &lt;enabled&gt;true&lt;/enabled&gt;
              &lt;/snapshots&gt;
          &lt;/repository&gt;
          &lt;repository&gt;
              &lt;id&gt;spring-milestones&lt;/id&gt;
              &lt;name&gt;Spring Milestones&lt;/name&gt;
              &lt;url&gt;https://repo.spring.io/milestone&lt;/url&gt;
              &lt;snapshots&gt;
                  &lt;enabled&gt;false&lt;/enabled&gt;
              &lt;/snapshots&gt;
          &lt;/repository&gt;
      &lt;/repositories&gt;
      &lt;pluginRepositories&gt;
          &lt;pluginRepository&gt;
              &lt;id&gt;spring-snapshots&lt;/id&gt;
              &lt;name&gt;Spring Snapshots&lt;/name&gt;
              &lt;url&gt;https://repo.spring.io/snapshot&lt;/url&gt;
              &lt;snapshots&gt;
                  &lt;enabled&gt;true&lt;/enabled&gt;
              &lt;/snapshots&gt;
          &lt;/pluginRepository&gt;
          &lt;pluginRepository&gt;
              &lt;id&gt;spring-milestones&lt;/id&gt;
              &lt;name&gt;Spring Milestones&lt;/name&gt;
              &lt;url&gt;https://repo.spring.io/milestone&lt;/url&gt;
              &lt;snapshots&gt;
                  &lt;enabled&gt;false&lt;/enabled&gt;
              &lt;/snapshots&gt;
          &lt;/pluginRepository&gt;
      &lt;/pluginRepositories&gt;
  &lt;/project&gt;
  </code></pre>