Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 21

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

  1. #11
    Join Date
    Nov 2007
    Posts
    177

    Default

    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>

  2. #12

    Default

    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

  3. #13
    Join Date
    Nov 2007
    Posts
    177

    Default

    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?

  4. #14

    Default

    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.

  5. #15
    Join Date
    Nov 2007
    Posts
    177

    Default

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

  6. #16

    Default

    Quote Originally Posted by balteo View Post
    .<init>() just refers to the default constructor of the class.
    OOPS. My bad. What are the other dependencies of your project? I am wondering if this could be an dependency management issue. It is kind of desperate but I cannot figure out any other reason for this.

  7. #17
    Join Date
    Nov 2007
    Posts
    177

    Default

    I'll have to do without my GlobalRepository for now... Thanks a lot for your time anyway. I appreciate.

  8. #18
    Join Date
    Nov 2007
    Posts
    177

    Default

    I finally found the reason for this exception: I had forgotten to mark the intermediate interface as @NoRepositoryBean. That solved it.
    P.S. I mistakenly filed a bug here https://jira.springsource.org/browse/DATAJPA-234 and realized the bug was on my side.

  9. #19

    Default

    Good the hear that you figured out what the problem was

  10. #20
    Join Date
    Nov 2007
    Posts
    177

    Default

    Thanks!!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •