title: How to fix NoSuchBeanDefinitionException when using CrudRepository from Spring Data Jpa?
body: <p>Collegues, I'am trying to get data from DB using Spring Crud Repository:</p>
  
  <pre><code>@Component
  public interface AssetsGapSortDAO  extends CrudRepository&lt;AssetsGapSortEntity, Integer&gt; {
     AssetsGapSortEntity getByIsin(String ISIN);
  }
  </code></pre>
  
  <p>JPA entity looks like:</p>
  
  <pre><code>@Entity
  @Table(name = "Assets", schema = "dbo", catalog = "")
  public class AssetsGapSortEntity {
      private BigInteger id;
  
      private String shortName;
      private String isin;
      private int registrationDate;
      /*Some other properties*/
  
      @Basic
      @Column(name = "id")
      public BigInteger getId() {
          return id;
      }
  
      public void setId(BigInteger id) {
          this.id = id;
      }
  
  
      @Id
      @Column(name = "ShortName")
      public String getShortName() {
          return shortName;
      }
  
      public void setShortName(String shortName) {
          this.shortName = shortName;
      }
  
  
      @Basic
      @Column(name = "ISIN")
      public String getIsin() {
          return isin;
      }
  
      public void setIsin(String isin) {
          this.isin = isin;
      }
  
      /*Equals and hashcode methods*/
  
  
      @Override
      public String toString() {
          ToStringStyle style = new NotNullToStringStyle();
          return ToStringBuilder.reflectionToString(this, style);
      }
  
  
  }
  </code></pre>
  
  <p>When i run jUnit test: </p>
  
  <pre><code>@RunWith(SpringJUnit4ClassRunner.class)
  @ContextConfiguration(classes = OlmeSmbConfig.class, loader = AnnotationConfigContextLoader.class)
  public class AssetsGapSortDAOTest {
      private static final Logger log = LoggerFactory.getLogger(ExtractionsDAOTest.class);
  
      @Autowired
      AssetsGapSortDAO assetsGapSortDAO;
  
      @Test
      public void getByIsin() throws Exception {
          log.info(assetsGapSortDAO.getByIsin("TT0W3888254").toString());
      }
  
  }
  </code></pre>
  
  <p>i receive the naxt stackTrace:</p>
  
  <pre><code>java.lang.IllegalStateException: Failed to load ApplicationContext
  
      at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124)
      at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:83)
  ....
      at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
  Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'assetInfoLoader': Unsatisfied dependency expressed through field 'assetsGapSortDAO'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.comp.olme.jpa.dao.GapSort.AssetsGapSortDAO' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
      at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:588)
      at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
      ....
      at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:116)
      ... 29 more
  Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.comp.olme.jpa.dao.GapSort.AssetsGapSortDAO' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1474)
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1102)
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1064)
      at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:585)
      ... 45 more
  </code></pre>
  
  <p>My config looks like:</p>
  
  <pre><code>@Configuration
  @EnableTransactionManagement
  @ComponentScan (basePackages = {"com.comp.olme"})
  @PropertySource("classpath:OlmeSmb-${env}.properties")
  @EnableScheduling
  public class OlmeSmbConfig {
  /*There are DataSource, EntityManagerFactory beans etc....*/
  }
  </code></pre>
  
  <p>When i use simple JPA everything works fine, but i would like to try CrudRepository.
  So the question is why i receive <code>NoSuchBeanDefinitionException</code> and how to fix it?
  Thank you. </p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>According to @javaguy advice i added to my config <code>@EnableJpaRepositories</code> annotation: </p>
  
  <pre><code>@EnableJpaRepositories(basePackages="com.comp.olme", entityManagerFactoryRef ="emGapSort", transactionManagerRef = "txManagerGapSort")
  </code></pre>
  
  <p>and the "NoSuchBeanDefinitionException" was fixed, but the new one raise:</p>
  
  <pre><code>Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name '(inner bean)#3e4e8fdf': Unsatisfied dependency expressed through method 'createSharedEntityManager' parameter 0: 
  Could not convert argument value of type [com.sun.proxy.$Proxy44] to required type [javax.persistence.EntityManagerFactory]: 
  Failed to convert value of type 'com.sun.proxy.$Proxy44 implementing org.hibernate.jpa.HibernateEntityManager,org.springframework.orm.jpa.EntityManagerProxy' to required type 'javax.persistence.EntityManagerFactory';
  nested exception is java.lang.IllegalStateException: 
  Cannot convert value of type 'com.sun.proxy.$Proxy44 implementing org.hibernate.jpa.HibernateEntityManager,org.springframework.orm.jpa.EntityManagerProxy' to required type 'javax.persistence.EntityManagerFactory': 
  no matching editors or conversion strategy found
      at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:723)
      at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:467)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1134)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1028)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
      at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:299)
      ... 58 more
  </code></pre>
  
  <p>May be it is because i have more than one datasource in Spring Config (there are two for different DB)? How to fix it?
  Sorry if it out of scope... </p>