title: Spring Data Repository - No qualifying bean Injection
body: <p>I'm new to Spring framework.
  I just started learning following various guides (<a href="http://spring.io/guides" rel="nofollow">http://spring.io/guides</a>) and I'm trying to complete the full tutorial about web services (<a href="http://spring.io/guides/tutorials/bookmarks/" rel="nofollow">http://spring.io/guides/tutorials/bookmarks/</a>).</p>
  
  <p>I'm quite stuck on the JPA Datasource definition, because I get the following error</p>
  
  
  
  <pre><code>Exception in thread "main" org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'init' defined in main.Application: Unsatisfied dependency expressed through constructor argument with index 0 of type [bookmarks.AccountRepository]: : No qualifying bean of type [bookmarks.AccountRepository] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [bookmarks.AccountRepository] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}
      at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:749)
      at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:464)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1111)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1006)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
      at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
      at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
      at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:762)
      at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)
      at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
      at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118)
      at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:691)
      at org.springframework.boot.SpringApplication.run(SpringApplication.java:321)
      at org.springframework.boot.SpringApplication.run(SpringApplication.java:961)
      at org.springframework.boot.SpringApplication.run(SpringApplication.java:950)
      at main.Application.main(Application.java:41)
  Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [bookmarks.AccountRepository] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:1308)
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1054)
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:949)
      at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:813)
      at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:741)
      ... 18 more
  </code></pre>
  
  
  
  <p>My main Application class is the following</p>
  
  
  
  <pre class="lang-java prettyprint-override"><code>@Configuration
  @ComponentScan
  @EnableAutoConfiguration
  public class Application {
  
      @Bean
      public CommandLineRunner init(AccountRepository accountRepository,
              BookmarkRepository bookmarkRepository) {
          System.out.println("Bean!");
          return (evt) -&gt; Arrays.asList(
                  "jhoeller,dsyer,pwebb,ogierke,rwinch,mfisher,mpollack,jlong".split(","))
                  .forEach(
                          a -&gt; {
                              Account account = accountRepository.save(new Account(a,
                                      "password"));
                              bookmarkRepository.save(new Bookmark(account,
                                      "http://bookmark.com/1/" + a, "A description"));
                              bookmarkRepository.save(new Bookmark(account,
                                      "http://bookmark.com/2/" + a, "A description"));
                          });
      }
  
      public static void main(String[] args) {
          SpringApplication.run(Application.class, args);
      }
  </code></pre>
  
  
  
  <p>And my pom.xml is</p>
  
  <pre class="lang-xml prettyprint-override"><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.test&lt;/groupId&gt;
      &lt;artifactId&gt;demo&lt;/artifactId&gt;
      &lt;version&gt;0.0.1&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.2.1.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;start-class&gt;demo.DemoApplication&lt;/start-class&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.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.data&lt;/groupId&gt;
              &lt;artifactId&gt;spring-data-jpa&lt;/artifactId&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;dependency&gt;
              &lt;groupId&gt;javax.inject&lt;/groupId&gt;
              &lt;artifactId&gt;javax.inject&lt;/artifactId&gt;
              &lt;version&gt;1&lt;/version&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 understand that the dependency injection framework doesn't find any implementation of the AccountRepository interface, which looks like</p>
  
  <pre class="lang-java prettyprint-override"><code>public interface AccountRepository extends JpaRepository&lt;Account, Long&gt; {
      Optional&lt;Account&gt; findByUsername(String username);
  }
  </code></pre>
  
  <p>But the framework should provide "a correct implementation" for the JpaRepository. This is the part I'm not understanding.</p>
  
  <p>Any help would be appreciated, in particular with a pointer where to study  in deep this framework.</p>
  
  <p>Thanks</p>
  
  <p><strong>UPDATE</strong>
  Adding @EnableJpaRepositories("bookmarks") to the Application class, solved the bean resolution issue. But now I get
  Caused by: java.lang.IllegalArgumentException: Not an managed type: class bookmarks.Account</p>
  
  <p>My Account entity class is</p>
  
  <pre class="lang-java prettyprint-override"><code>import javax.persistence.Entity;
  import javax.persistence.GeneratedValue;
  import javax.persistence.Id;
  import javax.persistence.OneToMany;
  
  import com.fasterxml.jackson.annotation.JsonIgnore;
  
  @Entity
  public class Account {
  
      @JsonIgnore
      public String password;
      public String username;
      @OneToMany(mappedBy="Account") 
      private Set&lt;Bookmark&gt; bookmarks = new HashSet&lt;&gt;();
      @Id @GeneratedValue 
      private Long id;
  
      public Account(String name, String password) {
          this.username = name;
          this.password = password;
      }
  
      Account() { } // jpa only
  
      // getters and setters
  }
  </code></pre>