title: Spring boot - UnsatisfiedDependencyException when using JPA to store and retrieve data in a relational database
body: <p>I've tried to build an application that uses Spring Data JPA to store and retrieve data in a relational database using Spring boot. I've been following guide on the spring site but continue to get this error. Does anyone know the cause of this or what I could do to fix it? Would be much appreciated, thanks.</p>
  
  <pre><code> org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'commandLine' defined in com.example.Application: Unsatisfied dependency expressed through constructor argument with index 0 of type [com.example.ImageRepository]: : Error creating bean with name 'imageRepository': Cannot create inner bean '(inner bean)#391c56d7' 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)#391c56d7': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'entityManagerFactory' is defined; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'imageRepository': Cannot create inner bean '(inner bean)#391c56d7' 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)#391c56d7': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'entityManagerFactory' is defined
  </code></pre>
  
  <p>The code is below: </p>
  
  <p>The repository:</p>
  
  <pre><code>package com.example;
  
  import java.util.List;
  
  import org.springframework.data.repository.CrudRepository;
  
   public interface ImageRepository extends CrudRepository&lt;Image, Long&gt; {
  
       List&lt;Image&gt; findByImageID(long imageID);
  }
  </code></pre>
  
  <p>The application:</p>
  
  <pre><code>@SpringBootApplication
  public class Application {
  
      private static final Logger log = LoggerFactory.getLogger(Application.class);
  
      public static void main(String[] args) {
          SpringApplication.run(Application.class, args);
      }
  
      @Bean
      public CommandLineRunner commandLine(ImageRepository repository) {
          return (args) -&gt; {
              repository.save(new Image("image1",50,40));
              repository.save(new Image("image2",50,40));
              repository.save(new Image("image3",50,40));
              repository.save(new Image("image4",50,40));
              repository.save(new Image("image5",50,40));
  
              log.info("Customers found with findAll():");
              log.info("-------------------------------");
              for (Image image : repository.findAll()) {
                  log.info(image.toString());
              }
              log.info("");
  
              Image image = repository.findOne(1L);
              log.info("Image found with findOne(1L):");
              log.info("--------------------------------");
              log.info(image.toString());
              log.info("");
  
              log.info("Image found with findByImageID(1):");
              log.info("--------------------------------------------");
              for (Image im : repository.findByImageID(1)) {
                  log.info(im.toString());
              }
              log.info("");
          };
      }
  }
  </code></pre>
  
  <p>The entity</p>
  
  <pre><code>@Entity
  public class Image {
  
      @Id
      @GeneratedValue(strategy=GenerationType.AUTO)
      private long imageID;
      private double lat, lon;
      private String description = "";
  
      protected Image() {}
  
      Image(String description, double lat, double lon)
      {
          this.description = description;
          this.lat = lat;
          this.lon = lon;
  
      }
      Image(double lat, double lon)
      {
          this.lat = lat;
          this.lon = lon;
      }
  
      public long getID()
      {
          return imageID;
      }
      public String getDesc()
      {
          return description;
      }
      public double getLat()
      {
          return lat;
      }
      public double getLon()
      {
          return lon;
      }
  
      @Override
      public String toString() {
          return String.format(
                  "Image[id=%d, description='%s', lat='%d', lon='%d']",
                  imageID, description,lat,lon);
      }
  
  }
  </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;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.3.2.RELEASE&lt;/version&gt;
          &lt;relativePath/&gt;
      &lt;/parent&gt;
  
      &lt;properties&gt;
          &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&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-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;dependency&gt;
              &lt;groupId&gt;org.thymeleaf&lt;/groupId&gt;
              &lt;artifactId&gt;thymeleaf&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.thymeleaf&lt;/groupId&gt;
              &lt;artifactId&gt;thymeleaf-spring4&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.data&lt;/groupId&gt;
              &lt;artifactId&gt;spring-data-jpa&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;javax.persistence&lt;/groupId&gt;
              &lt;artifactId&gt;persistence-api&lt;/artifactId&gt;
              &lt;version&gt;1.0.2&lt;/version&gt;
          &lt;/dependency&gt;   
  
          &lt;dependency&gt;
              &lt;groupId&gt;com.h2database&lt;/groupId&gt;
              &lt;artifactId&gt;h2&lt;/artifactId&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>