Announcement Announcement Module
Collapse
No announcement yet.
Need help with Introductions using @DeclareParents Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Need help with Introductions using @DeclareParents

    Hi -

    I have a DAO layer with a sample DAO class like the following :

    public class PersonDao extends DAOBase<Person> {
    ....
    }

    I would like to enhance the DAO layer with implementing an additional interface. I plan to do this using Introduction (@DeclareParents). The interface is defined as follows :

    public interface ICounter {
    <Context, T extends DTOBase> int count(Context ctx,
    DAOBase<T> dao,
    ICriteria cri);
    }

    It also has a default implementation CounterImpl.

    The aspect class which I call DAODecorator is as follows :

    @Aspect
    public class DAODecorator {

    @DeclareParents(value="com.x.y.z.dao.*+",
    defaultImpl=CounterImpl.class)
    public ICounter mixin;
    }

    The corresponding entries in config file are :

    <aop:aspectj-autoproxy/>

    <bean id="daoMixin"
    class="com.x.y.z.dao.DAODecorator">
    </bean>

    <bean id="daoImpl"
    class="com.x.y.z.DAOJPAImpl">
    </bean>

    <bean id="entreeDao"
    class="com.x.y.z.dao.EntreeDao"
    lazy-init="true"
    factory-method="makeDAO">
    <constructor-arg index="0"><ref bean="daoImpl"/></constructor-arg>
    </bean>

    Now when I run I get the following exception :

    org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'com.x.y.z.EntreeDaoTests': Error setting property values; nested exception is PropertyAccessExceptionsException (1 errors)
    Caused by: PropertyAccessExceptionsException (1 errors)
    org.springframework.beans.TypeMismatchException: Failed to convert property value of type [$Proxy14] to required type [com.x.y.z.dao.EntreeDao] for property 'entreeDao'; nested exception is java.lang.IllegalArgumentException: No matching editors or conversion strategy found
    Caused by: java.lang.IllegalArgumentException: No matching editors or conversion strategy found
    at org.springframework.beans.PropertyTypeConverter.co nvertIfNecessary(PropertyTypeConverter.java:209)
    at org.springframework.beans.PropertyTypeConverter.co nvertIfNecessary(PropertyTypeConverter.java:108)
    at org.springframework.beans.BeanWrapperImpl.setPrope rtyValue(BeanWrapperImpl.java:723)
    at org.springframework.beans.BeanWrapperImpl.setPrope rtyValue(BeanWrapperImpl.java:575)
    at org.springframework.beans.AbstractPropertyAccessor .setPropertyValue(AbstractPropertyAccessor.java:49 )
    at org.springframework.beans.AbstractPropertyAccessor .setPropertyValues(AbstractPropertyAccessor.java:6 8)
    at org.springframework.beans.AbstractPropertyAccessor .setPropertyValues(AbstractPropertyAccessor.java:5 7)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.applyPropertyValues(Abs tractAutowireCapableBeanFactory.java:816)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.populateBean(AbstractAu towireCapableBeanFactory.java:592)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.autowireBeanProperties( AbstractAutowireCapableBeanFactory.java:237)
    at org.springframework.test.AbstractDependencyInjecti onSpringContextTests.setUp(AbstractDependencyInjec tionSpringContextTests.java:201)
    at junit.framework.TestCase.runBare(TestCase.java:125 )
    at org.springframework.test.ConditionalTestCase.runBa re(ConditionalTestCase.java:69)
    at org.springframework.test.annotation.AbstractAnnota tionAwareTransactionalTests.access$001(AbstractAnn otationAwareTransactionalTests.java:44)
    at org.springframework.test.annotation.AbstractAnnota tionAwareTransactionalTests$1.run(AbstractAnnotati onAwareTransactionalTests.java:112)
    at org.springframework.test.annotation.AbstractAnnota tionAwareTransactionalTests.runTest(AbstractAnnota tionAwareTransactionalTests.java:177)
    at org.springframework.test.annotation.AbstractAnnota tionAwareTransactionalTests.runTestTimed(AbstractA nnotationAwareTransactionalTests.java:150)
    at org.springframework.test.annotation.AbstractAnnota tionAwareTransactionalTests.runBare(AbstractAnnota tionAwareTransactionalTests.java:108)
    at org.springframework.test.jpa.AbstractJpaTests.runB are(AbstractJpaTests.java:156)
    at org.springframework.test.jpa.AbstractJpaTests.runB are(AbstractJpaTests.java:235)
    at junit.framework.TestResult$1.protect(TestResult.ja va:106)
    at junit.framework.TestResult.runProtected(TestResult .java:124)
    at junit.framework.TestResult.run(TestResult.java:109 )
    at junit.framework.TestCase.run(TestCase.java:118)
    at junit.framework.TestSuite.runTest(TestSuite.java:2 08)
    at junit.framework.TestSuite.run(TestSuite.java:203)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.runTests(RemoteTestRunner.java:478)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.run(RemoteTestRunner.java:344)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.main(RemoteTestRunner.java:196)


    Any help will be appreciated. Also any pointer to a tutorial for using @DeclareParents and the entries in the config file will be appreciated. I went thru the example in Reference Documentation, but could not fix the problem.

    Best.
    - Debasish
Working...
X