Results 1 to 5 of 5

Thread: NoSuchMethodError:Aspect.aspectOf()

Hybrid View

  1. #1
    Join Date
    Oct 2009
    Posts
    21

    Default NoSuchMethodError:Aspect.aspectOf()

    Hi,

    I am trying to put LTW into an existing application.
    I have created a poc on how can I weave the advice around an object which is not managed by the Spring container, my pos works very well, and I am able to weave the advice around the target object.
    But when I am trying to apply the same concept into the real application(its a web app), it seems like aspectJ recognised my advice and target object to be adviced, but while trying to execute the advice method, it throws the following exception:

    15:17:25: ERROR: BaseCtrl.execute: Caught Throwable: foo/ProfilingAspect.aspectOf()Lfoo/ProfilingAspect;
    java.lang.NoSuchMethodError: foo/ProfilingAspect.aspectOf()Lfoo/ProfilingAspect;

    my aspect ie ProfilingAspect does not implement any aspectOf() method, I am not sure how can I implement it,also in my pos application,I did not implement any aspectOf() method in my aspect, and it works fine.

    Could somebody please help me to understand whats going wrong here?

    Following are my classes and config:

    Aspect class:-

    package foo;
    import org.aspectj.lang.ProceedingJoinPoint;
    import org.aspectj.lang.annotation.Around;
    import org.aspectj.lang.annotation.Aspect;
    import org.aspectj.lang.annotation.Pointcut;
    import org.springframework.util.StopWatch;
    @Aspect
    public class ProfilingAspect {

    @Around("methodsToBeProfiled()")
    public Object profile(ProceedingJoinPoint pjp) throws Throwable {
    StopWatch sw = new StopWatch(getClass().getSimpleName());
    System.out.println("my advice called........");
    try {
    sw.start(pjp.getSignature().getName());
    return pjp.proceed();
    } finally {
    sw.stop();
    System.out.println(sw.prettyPrint());
    }
    }

    @Pointcut("execution(public * com.mypackage..*.*(..))")
    public void methodsToBeProfiled(){}
    }

    aop.xml:-

    <!DOCTYPE aspectj PUBLIC
    "-//AspectJ//DTD//EN" "http://www.eclipse.org/aspectj/dtd/aspectj.dtd">
    <aspectj>
    <weaver options="-verbose -showWeaveInfo -debug">
    <!-- only weave classes in our application-specific packages -->
    <include within="com.mypackage.*"/>
    </weaver>
    <aspects>
    <!-- weave in just this aspect -->
    <aspect name="foo.ProfilingAspect"/>
    </aspects>
    </aspectj>

    beans definition:-

    <bean id="entitlementCalculationService"
    class="foo.StubEntitlementCalculationService"/>
    <bean id="aBean" class="foo.ProfilingAspect"/>
    <!-- this switches on the load-time weaving -->
    <context:load-time-weaver weaver-class="org.springframework.instrument.classloading .InstrumentationLoadTimeWeaver"/>

    following are the versions I am using:

    Spring 2.5
    aspectjrt-1.5.4.jar
    aspectjweaver-1.5.3.jar
    spring-agent-2.5.6.jar
    Thanks,
    Nitin.

  2. #2
    Join Date
    May 2007
    Location
    Saint Petersburg, Russian Federation
    Posts
    1,189

    Default

    It looks like your aspects logic is correctly weaved to target classes at runtime, however, 'raw' ProfilingAspect class is used, i.e. its byte-code is not transformed by aspectj ltw agent.

    You can try the following:
    • check aspectj ltw-dumped classes in order to verify that ProfilingAspect is processed by aspectj and its byte-code contains 'aspectOf()' method;
    • debug the place where the error is thrown in order to check that jvm tries to use the aspectj-advised ProfilingAspect class and not it's 'raw' version (for example because of class loader issues);
    • try compile-time aspectj weaving;

  3. #3
    Join Date
    Apr 2009
    Posts
    2

    Default

    Hi,

    I had a same problem. I found out that the weaving need to be enabled also for aspect classes in aop.xml file. In your case it is (see highlighted part):
    Code:
    <!DOCTYPE aspectj PUBLIC
            "-//AspectJ//DTD//EN" "http://www.eclipse.org/aspectj/dtd/aspectj.dtd">
    <aspectj>
        <weaver options="-verbose -showWeaveInfo -debug">
            <!-- only weave classes in our application-specific packages -->
            <include within="com.mypackage.*"/>
            <include within="foo.*"/>
        </weaver>
        <aspects>
            <!-- weave in just this aspect -->
            <aspect name="foo.ProfilingAspect"/>
        </aspects>
    </aspectj>
    Hope it helps.

  4. #4
    Join Date
    Mar 2008
    Location
    Wayzata, MN
    Posts
    15

    Default Thanks

    We were seeing this in Weblogic 10.3.3.0 using the -javaagent=/path/to/aspectjweaver.jar. We have a complex EAR with WAR and multiple EJBs inside.

    In any case, the solution of adding the aspects themselves to get instrumented solved our problem. Thanks for the pointer.

  5. #5
    Join Date
    Dec 2012
    Posts
    1

    Default

    It's worked for me! thanks.

    Quote Originally Posted by rozky View Post
    Hi,

    I had a same problem. I found out that the weaving need to be enabled also for aspect classes in aop.xml file. In your case it is (see highlighted part):
    Code:
    <!DOCTYPE aspectj PUBLIC
            "-//AspectJ//DTD//EN" "http://www.eclipse.org/aspectj/dtd/aspectj.dtd">
    <aspectj>
        <weaver options="-verbose -showWeaveInfo -debug">
            <!-- only weave classes in our application-specific packages -->
            <include within="com.mypackage.*"/>
            <include within="foo.*"/>
        </weaver>
        <aspects>
            <!-- weave in just this aspect -->
            <aspect name="foo.ProfilingAspect"/>
        </aspects>
    </aspectj>
    Hope it helps.

Posting Permissions

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