Announcement Announcement Module
Collapse
No announcement yet.
@AspectJ based Aspect working in Eclipse's JUnit runner, but not in Maven 1 Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • @AspectJ based Aspect working in Eclipse's JUnit runner, but not in Maven 1

    Hello all,

    I encounter a heavy problem with my JUnit 3 tests for my Apring-AOP based project. I defined an aspect with the @AspectJ syntax as follows:


    @Aspect
    public class ReportingAspect {
    <...>

    @Pointcut("execution(public foo.Response foo.Interface.getSomething(String, .., foo.SomeClass)) && args(theString, .., fooInstance)")
    void checkPC(String theString, SomeClass fooInstance) {}

    @Around("checkPC(theString, fooInstance)")
    public Object logStatisticsDataForFoo(ProceedingJoinPoint pjp, String theString, SomeClass fooInstance)
    throws Throwable {

    }
    }
    I defined a JUnit specific Spring context that uses this aspect. As long as I use the Eclipse JUnit runner everything is fine. But when I use Apache Maven 1 to run the unit test, I get the following stack trace:
    <BeanCreationExceptions...>


    Caused by: java.lang.IllegalArgumentException: warning no match for this type name: fooInstance[Xlint:invalidAbsoluteTypeName]
    at org.aspectj.weaver.tools.PointcutParser.parsePoint cutExpression(PointcutParser.java:315)
    at org.springframework.aop.aspectj.AspectJExpressionP ointcut.buildPointcutExpression(AspectJExpressionP ointcut.java:188)
    at org.springframework.aop.aspectj.AspectJExpressionP ointcut.checkReadyToMatch(AspectJExpressionPointcu t.java:175)
    at org.springframework.aop.aspectj.AspectJExpressionP ointcut.getClassFilter(AspectJExpressionPointcut.j ava:156)
    at org.springframework.aop.support.AopUtils.canApply( AopUtils.java:187)
    at org.springframework.aop.support.AopUtils.canApply( AopUtils.java:244)
    at org.springframework.aop.support.AopUtils.findAdvis orsThatCanApply(AopUtils.java:274)
    at org.springframework.aop.framework.autoproxy.Abstra ctAdvisorAutoProxyCreator.findEligibleAdvisors(Abs tractAdvisorAutoProxyCreator.java:85)
    at org.springframework.aop.framework.autoproxy.Abstra ctAdvisorAutoProxyCreator.getAdvicesAndAdvisorsFor Bean(AbstractAdvisorAutoProxyCreator.java:69)
    at org.springframework.aop.framework.autoproxy.Abstra ctAutoProxyCreator.postProcessAfterInitialization( AbstractAutoProxyCreator.java:277)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.applyBeanPostProcessors AfterInitialization(AbstractAutowireCapableBeanFac tory.java:318)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.initializeBean(Abstract AutowireCapableBeanFactory.java:1119)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:431)
    at org.springframework.beans.factory.support.Abstract BeanFactory$1.getObject(AbstractBeanFactory.java:2 54)
    at org.springframework.beans.factory.support.DefaultS ingletonBeanRegistry.getSingleton(DefaultSingleton BeanRegistry.java:144)
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:251)
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:163)
    at org.springframework.beans.factory.support.BeanDefi nitionValueResolver.resolveReference(BeanDefinitio nValueResolver.java:271)
    at org.springframework.beans.factory.support.BeanDefi nitionValueResolver.resolveValueIfNecessary(BeanDe finitionValueResolver.java:128)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.applyPropertyValues(Abs tractAutowireCapableBeanFactory.java:1047)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.populateBean(AbstractAu towireCapableBeanFactory.java:843)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:427)
    at org.springframework.beans.factory.support.Abstract BeanFactory$1.getObject(AbstractBeanFactory.java:2 54)
    at org.springframework.beans.factory.support.DefaultS ingletonBeanRegistry.getSingleton(DefaultSingleton BeanRegistry.java:144)
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:251)
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:163)
    When I remove the fooInstance argument from the signature, the parser is complaining about the string argument.

    I tried Spring 2.0.1 and 2.0.3. AspectJ ist 1.5.3, the asm library 2.2.3 and cglib is 2.1.3. I tried Maven 1.0.2 and Maven 1.1 RC3

    The Spring context contains the following section:

    <aop:aspectj-autoproxy/>
    <spring:bean id="reportingAspect" class="foo.reportingAspect">
    <springroperty name="publisher" ref="someReportingJMSPublisher"/>
    </spring:bean>

  • #2
    It looks like when you are using maven, you aren't specifying -g or -g:vars flag when compiling aspect. As a result, the pointcut parser is unable to see the argument names.

    The solution, of course, is to compile (at least) aspects using one of the flags. Alternative, you may want to use the argNames attribute in @Pointcut etc. annotations.

    -Ramnivas

    Comment

    Working...
    X