title: Spring boot with spring data repository - cannot autowire own repository
body: <p>I'm trying to create a new project with spring boot that will use spring data (spring repositories...), but I'm getting this error</p>
  
  <pre><code>org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'HQLTester': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.service.CompanyRepository com.example.HQLTester.companyRepository; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.service.CompanyRepository] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
      at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
      at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
      at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
      at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
      at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839) ~[spring-context-4.2.6.RELEASE.jar:4.2.6.RELEASE]
      at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538) ~[spring-context-4.2.6.RELEASE.jar:4.2.6.RELEASE]
      at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:766) [spring-boot-1.3.5.RELEASE.jar:1.3.5.RELEASE]
      at org.springframework.boot.SpringApplication.createAndRefreshContext(SpringApplication.java:361) [spring-boot-1.3.5.RELEASE.jar:1.3.5.RELEASE]
      at org.springframework.boot.SpringApplication.run(SpringApplication.java:307) [spring-boot-1.3.5.RELEASE.jar:1.3.5.RELEASE]
      at org.springframework.boot.SpringApplication.run(SpringApplication.java:1191) [spring-boot-1.3.5.RELEASE.jar:1.3.5.RELEASE]
      at org.springframework.boot.SpringApplication.run(SpringApplication.java:1180) [spring-boot-1.3.5.RELEASE.jar:1.3.5.RELEASE]
      at com.example.HqlTesterApplication.main(HqlTesterApplication.java:18) [classes/:na]
  Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.service.CompanyRepository com.example.HQLTester.companyRepository; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.service.CompanyRepository] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
      at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:573) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
      at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
      at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
      ... 16 common frames omitted
  Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.service.CompanyRepository] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:1373) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1119) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1014) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
      at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:545) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
      ... 18 common frames omitted
  </code></pre>
  
  <p>Here is my project structure </p>
  
  <p><a href="https://i.stack.imgur.com/D5QPS.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/D5QPS.jpg" alt="enter image description here"></a></p>
  
  <p>HqlTesterApplication.java</p>
  
  <pre><code>@SpringBootApplication
  @ComponentScan("com.*")
  @Configuration
  @EnableJpaRepositories("com.service.*")
  public class HqlTesterApplication {
  
      public static void main(String[] args) {
          SpringApplication.run(HqlTesterApplication.class, args);
      }
  
  }
  </code></pre>
  
  <p>HQLTester.java</p>
  
  <pre><code>@Service
  public class HQLTester {
  
      @Autowired
      CompanyRepository companyRepository;
  
      @PostConstruct
      void testHQL(){
          System.out.println("TEST");
          List&lt;Company&gt; companies = companyRepository.findCompanyWithEmployes2(new Date(), 1l);
          List&lt;Company&gt; companies2 = companyRepository.findCompanyWithEmployes(new Date(), 1l);
      }
  }
  </code></pre>
  
  <p>CompanyRepository.java</p>
  
  <pre><code>public interface CompanyRepository extends JpaRepository&lt;Company, Long&gt; {
  
      @Query(" SELECT c FROM Company c ,Employee e  LEFT JOIN FETCH c.employees emp WHERE e.id=emp.id and  e.hireDate &gt; :dateee and e.departureDate &lt; :dateee and c.id=:id")
      List&lt;Company&gt; findCompanyWithEmployes2(@Param("dateee") Date dateee, @Param("id") Long id);
  
      @Query(" SELECT c FROM Employee e  LEFT JOIN FETCH e.company c  WHERE     e.hireDate &gt; :dateee and e.departureDate &lt; :dateee and c.id=:id")
      List&lt;Company&gt; findCompanyWithEmployes(@Param("dateee") Date dateee, @Param("id") Long id);
  }
  </code></pre>
  
  <p>Company.java</p>
  
  <pre><code>@Entity
  public class Company {
  
      @Id
      Long id;
  
      String name;
  
      @OneToMany(mappedBy = "company", cascade = CascadeType.REFRESH, fetch = FetchType.LAZY)
      private Set&lt;Employee&gt; employees;
  
  }
  </code></pre>
  
  <p>Employee.java</p>
  
  <pre><code>@Entity
  public class Employee {
  
      @Id
      Long id;
  
      String name;
  
      Date hireDate;
  
      Date departureDate;
  
      @ManyToOne
      @JoinColumn(name = "companyId", insertable = false, updatable = false)
      Company company;
  
  }
  </code></pre>
  
  <p>application.properties</p>
  
  <pre><code>spring.datasource.url:jdbc:oracle:thin:@//myServer.com:1521/TESTDB
  spring.datasource.username=TESTUSER
  spring.datasource.password=TESTUSER
  spring.datasource.driver-class-name=oracle.jdbc.OracleDriver
  spring.jpa.hibernate.ddl-auto=none
  spring.jpa.database-platform=org.hibernate.dialect.Oracle10gDialect
  
  spring.jpa.show-sql = true
  logging.level.org.springframework.data=DEBUG
  </code></pre>
  
  <p>Could you please tell me what I missed to configure that my repository is not taken in context?</p>