Hello,
I use Spring data jpa and I am trying to add custom behaviour to all repositories as described here:
http://static.springsource.org/sprin...l-repositories
I encountered several issues:
-First, there is no such method as getDomainClass in the RepositoryMetadata class as described in the Spring documentation (see below):
I used the following method instead: getDomainType()Code:protected Object getTargetRepository(RepositoryMetadata metadata) { return new MyRepositoryImpl<T, I>((Class<T>) metadata.getDomainClass(), entityManager); }
Is this right?
-Second my application throws exceptions when tomcat starts. Here is the full stack trace:
Here is my custom global repository code:Code:org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'globalRepositoryImpl' defined in file [E:\users\jumartin\dev_sts\.metadata\.plugins\org.eclipse.wst.server.core\ tmp0\wtpwebapps\SuiviTRC\WEB-INF\classes\trc\suivi\repository\GlobalRepositoryImpl.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [trc.suivi.repository.GlobalRepositoryImpl]: No default constructor found; nested exception is java.lang.NoSuchMethodException: trc.suivi.repository.GlobalRepositoryImpl.<i nit>()
Here is my xml config:Code:public class GlobalRepositoryImpl<T, ID extends Serializable> extends SimpleJpaRepository<T, ID> implements GlobalRepository<T, ID> { private EntityManager em; public GlobalRepositoryImpl(Class<T> domainClass, EntityManager em) { super(domainClass, em); this.em = em; } public void sharedCustomMethod(ID id) { } }
I was not able to find any other sample on the web. Can anyone please help?Code:<repositories base-package="trc.suivi.repository" factory-class="trc.suivi.repository.GlobalRepositoryFactoryBean"> <repository id="pliRepository" /> <repository id="globalRepository" /> </repositories>
Regards,
J.


Reply With Quote
