Announcement Announcement Module
Collapse
No announcement yet.
Several issues with "adding custom behaviour to all repositories" in spring data jpa Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Several issues with "adding custom behaviour to all repositories" in spring data jpa

    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):
    Code:
    protected Object getTargetRepository(RepositoryMetadata metadata) {
          return new MyRepositoryImpl<T, I>((Class<T>) metadata.getDomainClass(), entityManager);
    }
    I used the following method instead: getDomainType()

    Is this right?


    -Second my application throws exceptions when tomcat starts. Here is the full stack trace:

    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 custom global repository code:

    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) {
    		
    	}
    
    }
    Here is my xml config:

    Code:
    <repositories base-package="trc.suivi.repository" factory-class="trc.suivi.repository.GlobalRepositoryFactoryBean">
    		<repository id="pliRepository" />
    		<repository id="globalRepository" />
    	</repositories>
    I was not able to find any other sample on the web. Can anyone please help?

    Regards,

    J.

  • #2
    Originally posted by balteo View Post
    I used the following method instead: getDomainType()

    Is this right?
    That is the correct method.

    Originally posted by balteo View Post
    Here is my xml config:

    Code:
    <repositories base-package="trc.suivi.repository" factory-class="trc.suivi.repository.GlobalRepositoryFactoryBean">
    		<repository id="pliRepository" />
    		<repository id="globalRepository" />
    	</repositories>
    This configuration does not match the one given in the reference documentation. Spring Data JPA will find your repositories automatically as long as the base-package is correct. Try changing your XML configuration to:

    Code:
    <repositories base-package="trc.suivi.repository" factory-class="trc.suivi.repository.GlobalRepositoryFactoryBean"/>

    Comment


    • #3
      Hello Loke,

      Thanks for taking the time to reply.

      I altered the XML config as you advised to this:

      Code:
      	<repositories base-package="trc.suivi.repository" factory-class="trc.suivi.repository.GlobalRepositoryFactoryBean">
      	</repositories>
      Here is what I get:
      Code:
      GRAVE: Exception lors de l'envoi de l'évènement contexte initialisé (context initialized) à l'instance de classe d'écoute (listener) org.springframework.web.context.ContextLoaderListener
      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>()
      	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:997)
      	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:943)
      	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485)
      	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
      	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
      	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
      	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
      	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
      	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585)
      	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)
      	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
      	at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:385)
      	at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:284)
      	at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)
      	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4681)
      	at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5184)
      	at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5179)
      	at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
      	at java.util.concurrent.FutureTask.run(FutureTask.java:138)
      	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
      	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
      	at java.lang.Thread.run(Thread.java:662)
      Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [trc.suivi.repository.GlobalRepositoryImpl]: No default constructor found; nested exception is java.la
      ng.NoSuchMethodException: trc.suivi.repository.GlobalRepositoryImpl.<init>()
      	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:72)
      	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:990)
      	... 21 more
      Caused by: java.lang.NoSuchMethodException: trc.suivi.repository.GlobalRepositoryImpl.<init>()
      	at java.lang.Class.getConstructor0(Class.java:2706)
      	at java.lang.Class.getDeclaredConstructor(Class.java:1985)
      	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:67)
      	... 22 more

      Comment


      • #4
        Hi,

        could you add the source code of the GlobalRepositoryFactoryBean class? Also, are you using Spring Data JPA 1.0.X or 1.1?

        Comment


        • #5
          Here is the code for GlobalRepositoryFactoryBean:
          Code:
          package trc.suivi.repository;
          
          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 GlobalRepositoryFactoryBean<R extends JpaRepository<T, I>, T, I extends Serializable> extends JpaRepositoryFactoryBean<R, T, I> {
          
          	protected RepositoryFactorySupport createRepositoryFactory(EntityManager entityManager) {
          		return new GlobalRepositoryFactory(entityManager);
          	}
          
          	private static class GlobalRepositoryFactory<T, I extends Serializable> extends JpaRepositoryFactory {
          
          		private EntityManager entityManager;
          
          		public GlobalRepositoryFactory(EntityManager entityManager) {
          			super(entityManager);
          			this.entityManager = entityManager;
          		}
          
          		protected Object getTargetRepository(RepositoryMetadata metadata) {
          			return new GlobalRepositoryImpl<T, I>((Class<T>) metadata.getDomainType(), entityManager);
          		}
          
          		protected Class<?> getRepositoryBaseClass(RepositoryMetadata metadata) {
          			return GlobalRepository.class;
          		}
          	}
          }
          I use: Spring data jpa: 1.1.0 & Spring data common: 1.3.0

          Regards,

          J.

          Comment


          • #6
            I found one problem from your repository factory bean. The method getRepositoryBaseClass returns the type of your base repository interface. It should return the type of your base repository implementation. Try changing this method to:

            Code:
            protected Class<?> getRepositoryBaseClass(RepositoryMetadata metadata) {
            	return GlobalRepositoryImpl.class;
            }
            Let me know if this did the trick.

            Comment


            • #7
              No luck...

              I changed to GlobalRepositoryImpl.class but it still gives me the following exception:

              Code:
              2012-07-20 13:24:55,125 [Thread-2] ERROR org.springframework.web.context.ContextLoader - Context initialization failed
              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>()
              	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:997)
              	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:943)
              	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485)
              	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
              	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
              	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
              	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
              	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
              	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585)
              	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)
              	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
              	at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:385)
              	at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:284)
              	at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)
              	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4681)
              	at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5184)
              	at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5179)
              	at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
              	at java.util.concurrent.FutureTask.run(FutureTask.java:138)
              	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
              	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
              	at java.lang.Thread.run(Thread.java:662)
              Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [trc.suivi.repository.GlobalRepositoryImpl]: No default constructor found; nested exception is java.la
              ng.NoSuchMethodException: trc.suivi.repository.GlobalRepositoryImpl.<init>()
              	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:72)
              	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:990)
              	... 21 more
              Caused by: java.lang.NoSuchMethodException: trc.suivi.repository.GlobalRepositoryImpl.<init>()
              	at java.lang.Class.getConstructor0(Class.java:2706)
              	at java.lang.Class.getDeclaredConstructor(Class.java:1985)
              	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:67)
              	... 22 more

              Comment


              • #8
                I forgot to include the code for GlobalRepositoryImpl:

                Here it is:
                Code:
                package trc.suivi.repository;
                
                import java.io.Serializable;
                
                import javax.persistence.EntityManager;
                
                import org.springframework.data.jpa.repository.support.SimpleJpaRepository;
                
                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) {
                		
                	}
                
                }

                Comment


                • #9
                  I am running out of ideas here. The only difference between your code and the code that is working for me is that I am using different constructor in my generic base repository. My constructor looks following:

                  Code:
                  public GenericBaseRepository(JpaEntityInformation<T, ID> entityMetadata, EntityManager entityManager) {
                          super(entityMetadata, entityManager);
                  }
                  Here is the getTargetRepository() method of my repository factory bean.

                  Code:
                  @Override
                  protected Object getTargetRepository(RepositoryMetadata metadata) {
                              return new GenericBaseRepository<T, I>((JpaEntityInformation<T,I>) getEntityInformation(metadata.getDomainType()), entityManager);
                  }
                  If does this does not help, you could add your application context configuration here. It might have some other clues about the problem.

                  Comment


                  • #10
                    Here is my the changed code:

                    Code:
                    	public GlobalRepositoryImpl(JpaEntityInformation<T, ID> entityMetadata, EntityManager entityManager) {
                    		super(entityMetadata, entityManager);
                    	}
                    Code:
                    	@Override
                    		protected Object getTargetRepository(RepositoryMetadata metadata) {
                    		            return new GlobalRepositoryImpl<T, I>((JpaEntityInformation<T,I>) getEntityInformation(metadata.getDomainType()), entityManager);
                    		}
                    and the resulting exception:

                    Code:
                    GRAVE: Exception lors de l'envoi de l'évènement contexte initialisé (context initialized) à l'instance de classe d'écoute (listener) org.springframework.web.context.ContextLoaderListener
                    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>()
                    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:997)
                    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:943)
                    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485)
                    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
                    	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
                    	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
                    	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
                    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
                    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585)
                    	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)
                    	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
                    	at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:385)
                    	at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:284)
                    	at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)
                    	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4681)
                    	at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5184)
                    	at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5179)
                    	at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
                    	at java.util.concurrent.FutureTask.run(FutureTask.java:138)
                    	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
                    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
                    	at java.lang.Thread.run(Thread.java:662)
                    Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [trc.suivi.repository.GlobalRepositoryImpl]: No default constructor found; nested exception is java.la
                    ng.NoSuchMethodException: trc.suivi.repository.GlobalRepositoryImpl.<init>()
                    	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:72)
                    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:990)
                    	... 21 more
                    Caused by: java.lang.NoSuchMethodException: trc.suivi.repository.GlobalRepositoryImpl.<init>()
                    	at java.lang.Class.getConstructor0(Class.java:2706)
                    	at java.lang.Class.getDeclaredConstructor(Class.java:1985)
                    	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:67)
                    	... 22 more

                    Comment


                    • #11
                      I forgot to mention that I use Roo.

                      Here are the relevant config files:

                      applicationContext.xml:
                      Code:
                      <?xml version="1.0" encoding="UTF-8" standalone="no"?>
                      <beans xmlns="http://www.springframework.org/schema/beans"
                      	xmlns:aop="http://www.springframework.org/schema/aop"
                      	xmlns:context="http://www.springframework.org/schema/context"
                      	xmlns:jee="http://www.springframework.org/schema/jee"
                      	xmlns:tx="http://www.springframework.org/schema/tx"
                      	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                      	xmlns:mvc="http://www.springframework.org/schema/mvc"
                      	xsi:schemaLocation="http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.1.xsd
                      		http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
                      		http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
                      		http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
                      		http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
                      		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">
                      	<!-- This will automatically locate any and all property files you have 
                      		within your classpath, provided they fall under the META-INF/spring directory. 
                      		The located property files are parsed and their values can then be used within 
                      		application context files in the form of ${propertyKey}. -->
                      	<context:property-placeholder location="classpath*:META-INF/spring/*.properties" />
                      	<!-- Turn on AspectJ @Configurable support. As a result, any time you instantiate 
                      		an object, Spring will attempt to perform dependency injection on that object. 
                      		This occurs for instantiation via the "new" keyword, as well as via reflection. 
                      		This is possible because AspectJ is used to "weave" Roo-based applications 
                      		at compile time. In effect this feature allows dependency injection of any 
                      		object at all in your system, which is a very useful feature (without @Configurable 
                      		you'd only be able to dependency inject objects acquired from Spring or subsequently 
                      		presented to a specific Spring dependency injection method). Roo applications 
                      		use this useful feature in a number of areas, such as @PersistenceContext 
                      		injection into entities. -->
                      	<context:spring-configured />
                      	<!-- This declaration will cause Spring to locate every @Component, @Repository 
                      		and @Service in your application. In practical terms this allows you to write 
                      		a POJO and then simply annotate the new POJO as an @Service and Spring will 
                      		automatically detect, instantiate and dependency inject your service at startup 
                      		time. Importantly, you can then also have your new service injected into 
                      		any other class that requires it simply by declaring a field for your service 
                      		inside the relying class and Spring will inject it. Note that two exclude 
                      		filters are declared. The first ensures that Spring doesn't spend time introspecting 
                      		Roo-specific ITD aspects. The second ensures Roo doesn't instantiate your 
                      		@Controller classes, as these should be instantiated by a web tier application 
                      		context. Refer to web.xml for more details about the web tier application 
                      		context setup services. Furthermore, this turns on @Autowired, @PostConstruct 
                      		etc support. These annotations allow you to use common Spring and Java Enterprise 
                      		Edition annotations in your classes without needing to do any special configuration. 
                      		The most commonly used annotation is @Autowired, which instructs Spring to 
                      		dependency inject an object into your class. -->
                      	<context:component-scan base-package="trc.suivi">
                      		<context:exclude-filter expression=".*_Roo_.*"
                      			type="regex" />
                      		<context:exclude-filter expression="org.springframework.stereotype.Controller"
                      			type="annotation" />
                      	</context:component-scan>
                      	<bean class="org.apache.commons.dbcp.BasicDataSource"
                      		destroy-method="close" id="dataSource">
                      		<property name="driverClassName" value="${database.driverClassName}" />
                      		<property name="url" value="${database.url}" />
                      		<property name="username" value="${database.username}" />
                      		<property name="password" value="${database.password}" />
                      		<property name="testOnBorrow" value="true" />
                      		<property name="testOnReturn" value="true" />
                      		<property name="testWhileIdle" value="true" />
                      		<property name="timeBetweenEvictionRunsMillis" value="1800000" />
                      		<property name="numTestsPerEvictionRun" value="3" />
                      		<property name="minEvictableIdleTimeMillis" value="1800000" />
                      		<property name="validationQuery" value="SELECT 1" />
                      	</bean>
                      	<bean class="org.springframework.orm.jpa.JpaTransactionManager"
                      		id="transactionManager">
                      		<property name="entityManagerFactory" ref="entityManagerFactory" />
                      	</bean>
                      	<tx:annotation-driven mode="aspectj"
                      		transaction-manager="transactionManager" />
                      	<bean
                      		class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
                      		id="entityManagerFactory">
                      		<property name="persistenceUnitName" value="persistenceUnit" />
                      		<property name="dataSource" ref="dataSource" />
                      	</bean>
                      </beans>
                      applicationContext-jpa.xml

                      Code:
                      <?xml version="1.0" encoding="UTF-8"?>
                      <beans:beans xmlns:beans="http://www.springframework.org/schema/beans"
                      	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/data/jpa"
                      	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd">
                      
                      	<repositories base-package="trc.suivi.repository" factory-class="trc.suivi.repository.GlobalRepositoryFactoryBean"><!--  -->
                      	</repositories>
                      
                      </beans:beans>

                      Comment


                      • #12
                        I noticed one more difference. The visibility of your GlobalRepositoryFactory is set private. In my code the visibility of the repository factory inner class is set to protected. Try this:

                        Code:
                        protected static class GlobalRepositoryFactory<T, I extends Serializable> extends JpaRepositoryFactory

                        Comment


                        • #13
                          Still no luck. Very same exception.

                          I am pretty sure the exception I get has to do with the default configuration provided by Roo but I am not sure where to look...

                          What do you think?

                          Comment


                          • #14
                            I have no experience from ROO but it would be strange if it would be cause of this because this exception:

                            Code:
                            Caused by: java.lang.NoSuchMethodException: trc.suivi.repository.GlobalRepositoryImpl.<init>()
                            tells us the root cause of the problem is that init() method is not found from the GlobalRepositoryImpl class. This is a bit weird because my base repository does not have init() method either and the code is working.

                            Comment


                            • #15
                              .<init>() just refers to the default constructor of the class.

                              Comment

                              Working...
                              X