Announcement Announcement Module
Collapse
No announcement yet.
AspectJ, AJDT and Spring-AOP - exception initializing Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • AspectJ, AJDT and Spring-AOP - exception initializing

    Hi,
    Looking at these forums,scanning the internet for a problem with my test application
    Environment
    Spring 2.5.6,Eclipse 3.5 + AJDT 2.0 + AspectJ 1.6.5, Junit 4.4

    Aspects
    Aspect using Spring-AOP annotation to enhance my basic DAO's

    Code:
    @Aspect
    public class DAOPropertySupportAdvice implements DAOPropertySupport {
    .....
    @Around("be.titan.hesperus.aspects.SystemArchitecture.DAOgetNew() && @target(be.titan.hesperus.annotations.DynamicPropertySupport)")
    	public Object addNewDynamicProperties(ProceedingJoinPoint pjp)
    			throws Throwable {
    ...
    @Around("be.titan.hesperus.aspects.SystemArchitecture.DAOgetById() && @target(be.titan.hesperus.annotations.DynamicPropertySupport)")
    	public Object addDynamicPropertiesById(ProceedingJoinPoint pjp)
    			throws Throwable {
    ...
    MockDAO
    Test DAO has it's methods advised by previous Aspect. (verified in AJDT)

    Code:
    @DynamicPropertySupport
    public class MockDAO implements GenericDAO<MockPO, String> {
    ...	
    	public MockPO getNew() {		
                return new MockPO();
    ...
    MockPO in above code is enhanced by AspectJ CTW. (=OK)

    Code:
    Unit test
    I wrote a unit test to verify the weaving in the DAO class

    Code:
    @RunWith(SpringJUnit4ClassRunner.class)
    @ContextConfiguration(locations = { "classpath:spring/testApplicationContext.xml" })
    public class MockTest {
    	@Autowired(required = true)
    	protected MockDAO mockDAO;
    
    	@Test
    	public void testCreateMockWithAdvice() throws Exception {
    		MockPO mockPO = new MockPO();
    		Assert.assertTrue(mockPO instanceof PropertyContainer);
    	}
    
    	@Test
    	public void testCreateMockWithProperties() throws Exception {
    		MockPO mockPO = mockDAO.getNew();		
    		Assert.assertTrue(((PropertyContainer) mockPO).existProperty("mockLimit"));
    	}
    }
    applicationcontext
    And this is the xml-file used in the unittest

    Code:
    .....
    	<aop:aspectj-autoproxy>
    		<aop:include name="PropertySupportAdvice" />
    	</aop:aspectj-autoproxy>
    
    	<!-- aspect for handling dynamic properties by DAO classes -->
    	<bean id="PropertySupportAdvice"
    		class="be.titan.hesperus.general.persistence.dynamicproperty.DAOPropertySupportAdvice">
    		<constructor-arg
    			type="be.titan.hesperus.general.persistence.dynamicproperty.PropertyHandler">
    			<bean id="supportPropertyHandler"
    				class="be.titan.hesperus.general.persistence.dynamicproperty.JdbcPropertyHandler">
    				<constructor-arg>
    					<ref bean="dataSource" />
    				</constructor-arg>
    			</bean>
    		</constructor-arg>
    
    		<property name="propertyMapperMap">
    			<util:map>
    				<entry key="be.titan.hesperus.datalayer.organizationmanager.PartyInfo"
    					value="partyPropertyMapper" />
    				<entry key="be.titan.hesperus.general.persistence.MockPO"
    					value="mockPropertyMapper" />
    			</util:map>
    		</property>
    	</bean>
    
    ...
    Error
    When running the unittest the first test is OK but 2nd one gives the below stacktrace. I'm missing a default constructor which is correct as I need to initialize the PropertySupportAdvice. Anybody have a clue how to solve this?

    Code:
    org.aspectj.lang.NoAspectBoundException: Exception while initializing be.titan.hesperus.general.persistence.dynamicproperty.DAOPropertySupportAdvice: java.lang.NoSuchMethodError: be.titan.hesperus.general.persistence.dynamicproperty.DAOPropertySupportAdvice: method <init>()V not found
    	at be.titan.hesperus.general.persistence.dynamicproperty.DAOPropertySupportAdvice.aspectOf(DAOPropertySupportAdvice.java:1)
    	at be.titan.hesperus.general.persistence.MockDAO.getNew(MockDAO.java:1)
    	at be.titan.hesperus.general.persistence.MockTest.testCreateMockWithProperties(MockTest.java:45)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    	at java.lang.reflect.Method.invoke(Method.java:597)
    	at org.springframework.test.context.junit4.SpringTestMethod.invoke(SpringTestMethod.java:163)
    	at org.springframework.test.context.junit4.SpringMethodRoadie.runTestMethod(SpringMethodRoadie.java:233)
    	at org.springframework.test.context.junit4.SpringMethodRoadie$RunBeforesThenTestThenAfters.run(SpringMethodRoadie.java:333)
    	at org.springframework.test.context.junit4.SpringMethodRoadie.runWithRepetitions(SpringMethodRoadie.java:217)
    	at org.springframework.test.context.junit4.SpringMethodRoadie.runTest(SpringMethodRoadie.java:197)
    	at org.springframework.test.context.junit4.SpringMethodRoadie.run(SpringMethodRoadie.java:143)
    	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.invokeTestMethod(SpringJUnit4ClassRunner.java:142)
    	at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51)
    	at org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44)
    	at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
    	at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
    	at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
    	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
    	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
    Caused by: java.lang.NoSuchMethodError: be.titan.hesperus.general.persistence.dynamicproperty.DAOPropertySupportAdvice: method <init>()V not found
    	at be.titan.hesperus.general.persistence.dynamicproperty.DAOPropertySupportAdvice.ajc$postClinit(DAOPropertySupportAdvice.java:1)
    	at be.titan.hesperus.general.persistence.dynamicproperty.DAOPropertySupportAdvice.<clinit>(DAOPropertySupportAdvice.java:1)
    	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    	at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    	at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:100)
    	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:87)
    	at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:248)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:925)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:835)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:440)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
    	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
    	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:221)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:429)
    	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:729)
    	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:381)
    	at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:84)
    	at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:42)
    	at org.springframework.test.context.TestContext.loadApplicationContext(TestContext.java:173)
    	at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:199)
    	at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:109)
    	at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75)
    	at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:255)
    	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:93)
    	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.invokeTestMethod(SpringJUnit4ClassRunner.java:130)
    	... 11 more
    Thanks in advance,
    Renaat

  • #2
    ... and if I switch over to spring LTW (using the -javaagent:spring-agent.jar parameter) I get the an enormous stacktrace but this is the most important part I guess

    Code:
    Unable to continue, this version of AspectJ supports classes built with weaver version 5.0 but the class be.titan.hesperus.general.persistence.MockPO is version 6.0
    So, then I came to the conclusion that I wasn't using Spring 2.5.6 but rather 2.5.5. Upgraded. Run my UnitTest and I get :

    Code:
    Jul 12, 2009 12:18:06 AM org.aspectj.weaver.tools.Jdk14Trace error
    SEVERE: be/titan/hesperus/general/persistence/MockDAO
    org.aspectj.weaver.BCException: malformed org.aspectj.weaver.WeaverState attribute (length:5884)org.aspectj.weaver.BCException: bad kind: 11
    when processing type mungers 
    when weaving
    This is my aop.xml file
    Code:
    <!DOCTYPE aspectj PUBLIC
            "-//AspectJ//DTD//EN" "http://www.eclipse.org/aspectj/dtd/aspectj.dtd">
    <aspectj>
        <weaver>
            <!-- only weave classes in our application-specific packages -->
            <include within="be.titan.hesperus.general.persistence.*"/>
        </weaver>
        <aspects>
            <!-- weave in just this aspect -->
            <!-- aspect name="foo.ProfilingAspect"/ -->
            <aspect name="be.titan.hesperus.general.persistence.dynamicproperty.DAOPropertySupportAdvice"/>
            <aspect name="be.titan.hesperus.general.persistence.lifecyclesupport.DAOLifecycleSupportAdvice"/>
        </aspects>
      </aspectj>
    It also tries to weave an additional class not mentioned in the aop.xml but I guess this has to do with the @Configurable annotation....

    Cheers,
    Renaat

    Comment


    • #3
      Solved it

      Ok, finally managed it solve it myself. I dropped the idea of LTW and went back to my original solution.
      The problem was indeed that AspectJ always uses the default constructor which I didn't have (cought up on my reading on AspectJ). So I dropped the constructor with the arguments and added a new setter operation to the aspect.
      In the XML-declaration I added factory-method="aspectOf". A couple of minutes later I had my test running like a charm.

      Cheers,
      Renaat

      Comment


      • #4
        I had exactly the same problem, but in my case I cannot change the constructor, because I was extending some class. In my case addition of aspectjrt dependency (1.6.12) solved the problem (Spring 3.1.2).

        Comment

        Working...
        X