Spring JPA 2.0 Repository / Factory not working <p>I'm trying to implement a custom java Spring JPA repository, as described in the <a href="http://static.springsource.org/spring-data/data-jpa/docs/current/reference/html/repositories.html#repositories.custom-implementations" rel="nofollow">Spring documentation</a>. It seems that my spring config insists on creating the repositories in the standard way, instead of using the given MyRepositoryFactoryBean, giving me </p> <pre><code>Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.myapp.repository.impl.DocumentRepositoryImpl]: No default constructor found; nested exception is java.lang.NoSuchMethodException: com.myapp.repository.impl.DocumentRepositoryImpl.&lt;init&gt;() at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:83) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1006) ... 43 more Caused by: java.lang.NoSuchMethodException: com.myapp.repository.impl.DocumentRepositoryImpl.&lt;init&gt;() at java.lang.Class.getConstructor0(Class.java:2730) at java.lang.Class.getDeclaredConstructor(Class.java:2004) at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:78) </code></pre> <p>I'm using Spring 3.2.2-RELEASE and spring-data-jpa-1.3.2-RELEASE, which is the latest if I'm correct. Here's my spring config:<br> </p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:util="http://www.springframework.org/schema/util" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.2.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd"&gt; &lt;import resource="spring-repository-config.xml"/&gt; &lt;import resource="spring-security-config.xml"/&gt; &lt;context:component-scan base-package="com.myapp.web.controller"/&gt; &lt;context:component-scan base-package="com.myapp.webservice.controller"/&gt; </code></pre> <p>And here's the spring-repository-config.xml: </p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;beans:beans xmlns="http://www.springframework.org/schema/data/jpa" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.3.xsd"&gt; &lt;repositories base-package="com.myapp.repository" factory-class="com.myapp.repository.impl.MyRepositoryFactoryBean"/&gt; &lt;!-- entity-manager-factory-ref="entityManagerFactory" transaction-manager-ref="transactionManager" --&gt; </code></pre> <p></p> <p>If've added debug breakpoints in all the methods of the com.myapp.repository.impl.MyRepositoryFactoryBean class, but these were not called.</p> <p>The basic interface, just like in the example</p> <pre><code>package com.myapp.repository.impl; @NoRepositoryBean public interface MyRepository&lt;T, ID extends Serializable&gt; extends JpaRepository&lt;T, ID&gt; { </code></pre> <p>The base implementation: </p> <pre><code>package com.myapp.repository.impl; @NoRepositoryBean public class MyRepositoryImpl&lt;T, ID extends Serializable&gt; extends SimpleJpaRepository&lt;T, ID&gt; implements MyRepository&lt;T, ID&gt; { private EntityManager entityManager; public MyRepositoryImpl(Class&lt;T&gt; domainClass, EntityManager entityManager) { super(domainClass, entityManager); // This is the recommended method for accessing inherited class dependencies. this.entityManager = entityManager; } public void sharedCustomMethod(ID id) { // implementation goes here } } </code></pre> <p>And the factory: </p> <pre><code>package com.myapp.repository.impl; import java.io.Serializable; import javax.persistence.EntityManager; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.support.JpaRepositoryFactory; import org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean; import org.springframework.data.repository.core.RepositoryMetadata; import org.springframework.data.repository.core.support.RepositoryFactorySupport; public class MyRepositoryFactoryBean&lt;R extends JpaRepository&lt;T, I&gt;, T, I extends Serializable&gt; extends JpaRepositoryFactoryBean&lt;R, T, I&gt; { protected RepositoryFactorySupport createRepositoryFactory(EntityManager entityManager) { return new MyRepositoryFactory(entityManager); } private static class MyRepositoryFactory&lt;T, I extends Serializable&gt; extends JpaRepositoryFactory { private EntityManager entityManager; public MyRepositoryFactory(EntityManager entityManager) { super(entityManager); this.entityManager = entityManager; } protected Object getTargetRepository(RepositoryMetadata metadata) { return new MyRepositoryImpl&lt;T, I&gt;((Class&lt;T&gt;) metadata.getDomainType(), entityManager); } protected Class&lt;?&gt; getRepositoryBaseClass(RepositoryMetadata metadata) { // The RepositoryMetadata can be safely ignored, it is used by the JpaRepositoryFactory // to check for QueryDslJpaRepository's which is out of scope. return MyRepositoryImpl.class; } } } </code></pre> <p>My repositories interfaces are defines as: </p> <pre><code>package com.myapp.repository; public interface DocumentRepository { // extends MyRepository&lt;Document, Long&gt; public Document findByDocumentHash(String hashCode); public Document findById(long id); } </code></pre> <p>And the implementation is</p> <pre><code>package com.myapp.repository.impl; import java.io.Serializable; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; public class DocumentRepositoryImpl&lt;Document, ID extends Serializable&gt; extends MyRepositoryImpl&lt;Document, Serializable&gt; { private static final long serialVersionUID = 1L; public DocumentRepositoryImpl(Class&lt;Document&gt; domainClass, EntityManager entityManager) { super(domainClass, entityManager); } </code></pre> <p>And I use these repositories as autowired refernces in my controllers: </p> <pre><code>package com.myapp.web.controller; @Controller @RequestMapping(value = "/documents") public class DocumentController { @Autowired private DocumentRepository documentRepository; @RequestMapping(method = RequestMethod.GET) public ModelAndView list(HttpServletRequest request) { this.documentRepository. ... } </code></pre> <p>I've looked at various resources on the web like <a href="http://stackoverflow.com/questions/15140867/cant-autowire-repositories-created-by-jparepositoryfactorybean">this one</a>, but I can't tell the difference with my code. Any hints are more than welcome!</p>