title: spring jpa custom repository not working
body: <p>Trying to create a custom repository implementation with spring and getting the following 
  error: </p>
  
  <pre><code>caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No
    qualifying bean of type [com.mynamespace.domain.repository.GenericRepositoryImpl] 
    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)} 
  </code></pre>
  
  <p>Here is my code (download it from <a href="https://dl.dropboxusercontent.com/u/11115278/src-spring-problem/SpringSimple.zip.renameit" rel="nofollow">https://dl.dropboxusercontent.com/u/11115278/src-spring-problem/SpringSimple.zip.renameit</a>): </p>
  
  <pre><code>public class GenericRepositoryImpl&lt;T, ID extends Serializable&gt; extends
          SimpleJpaRepository&lt;T, ID&gt; implements GenericRepository&lt;T, ID&gt; {
  
      private static final long serialVersionUID = 1L;
  
      private EntityManager entityManager;
      private Class&lt;T&gt; domainClass;
  
      public GenericRepositoryImpl(Class&lt;T&gt; domainClass, EntityManager entityManager) {
  
          super(domainClass, entityManager);
  
          this.entityManager = entityManager;
          this.domainClass = domainClass;
      }
  
      public List&lt;T&gt; someCustomMethod(Long orgId) {
  
          return super.findAll();
      }
  }
  </code></pre>
  
  <p>The intermediate interface </p>
  
  <pre><code>@NoRepositoryBean
  public interface GenericRepository&lt;T, ID extends Serializable&gt; extends JpaRepository&lt;T, ID&gt; {
  
    List&lt;T&gt; someCustomMethod(Long orgId);
  }
  </code></pre>
  
  <p>Custom Factory bean </p>
  
  <pre><code>public class GenericRepositoryFactoryBean&lt;R extends JpaRepository&lt;T, I&gt;, T, I extends Serializable&gt;
    extends JpaRepositoryFactoryBean&lt;R, T, I&gt; {
  
    static Logger logger = LoggerFactory.getLogger(GenericRepositoryFactoryBean.class);
  
    protected RepositoryFactorySupport createRepositoryFactory(EntityManager entityManager) {
  
      logger.debug("#### GenericRepositoryFactoryBean : createRepositoryFactory #################");
      return new GenericRepositoryFactory(entityManager);
    }
  
    protected static class GenericRepositoryFactory&lt;T, I extends Serializable&gt; extends JpaRepositoryFactory {
  
      private EntityManager entityManager;
  
      public GenericRepositoryFactory(EntityManager entityManager) {
        super(entityManager);
        logger.debug("#### GenericRepositoryFactory : createRepositoryFactory #################");
        this.entityManager = entityManager;
      }
  
      protected Object getTargetRepository(RepositoryMetadata metadata) {
        logger.debug("#### GenericRepositoryFactory : getTargetRepository #################");
         logger.debug("#### GenericRepositoryFactory : getTargetRepository metadata.domainType - %1 entityManager - %2",metadata.getDomainType(),entityManager);
        return new GenericRepositoryImpl&lt;T, I&gt;((Class&lt;T&gt;) metadata.getDomainType(), entityManager);
      }
  
      protected Class&lt;?&gt; getRepositoryBaseClass(RepositoryMetadata metadata) {
        logger.debug("#### GenericRepositoryFactory : getRepositoryBaseClass #################");
        // The RepositoryMetadata can be safely ignored, it is used by the JpaRepositoryFactory
        // to check for QueryDslJpaRepository's which is out of scope.
        return GenericRepositoryImpl.class;
      }
    }
  }
  </code></pre>
  
  <p>Spring configuration </p>
  
  <pre><code>&lt;jpa:repositories base-package="com.mynamespace.domain.repository" 
    factory-class="com.mynamespace.domain.factory.GenericRepositoryFactoryBean"/&gt; 
  
  &lt;bean id="entityManagerFactory"
    class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt;
    &lt;property name="persistenceUnitName" value="Mypu" /&gt;
    &lt;property name="dataSource" &gt;
      &lt;jee:jndi-lookup id="dataSoruce" jndi-name="java:comp/env/jdbc/MyDS" /&gt;
    &lt;/property&gt;
    &lt;property name="packagesToScan" value="com.mynamespace.domain.model" /&gt;
    &lt;property name="jpaVendorAdapter"&gt;
        &lt;bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"&gt;
            &lt;property name="generateDdl" value="false"/&gt;
            &lt;property name="showSql" value="false"/&gt;
            &lt;property name="databasePlatform" value="org.hibernate.dialect.PostgreSQLDialect"/&gt;
        &lt;/bean&gt;
    &lt;/property&gt;
  &lt;/bean&gt;
  
  &lt;!--TransactionManager--&gt;
  &lt;bean id="txManager" class="org.springframework.orm.jpa.JpaTransactionManager"&gt;
    &lt;property name="entityManagerFactory" ref="entityManagerFactory" /&gt;
  &lt;/bean&gt;
  
  &lt;tx:annotation-driven transaction-manager="txManager"/&gt;
  </code></pre>
  
  <p>Additional info: I'm using Spring MVC, I have a config file for Spring MVC and another files for data and this is my Spring MVC file: </p>
  
  <pre><code>&lt;beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context"
      xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
          http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
          http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"&gt;
  
      &lt;import resource="classpath:spring/*.xml"/&gt;
      &lt;context:component-scan base-package="com.mynamespace.controllers"/&gt;
  
      &lt;mvc:annotation-driven /&gt;
      &lt;mvc:resources mapping="/css/**" location="/WEB-INF/resources/css/" /&gt;
      &lt;mvc:resources mapping="/js/**" location="/WEB-INF/resources/js/" /&gt;
      &lt;mvc:resources mapping="/images/**" location="/WEB-INF/resources/images/" /&gt;
      &lt;mvc:resources mapping="/font/**" location="/WEB-INF/resources/font/" /&gt;
  
      &lt;bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
              &lt;!-- Example: a logical view name of 'showMessage' is mapped to '/WEB-INF/jsp/showMessage.jsp' --&gt;
              &lt;property name="prefix" value="/WEB-INF/view/"/&gt;
              &lt;property name="suffix" value=".jsp"/&gt;
      &lt;/bean&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>Is not working :( any help?</p>