NoSuchMethodError aspectOf () at runtime from a building using iajc

We used aspectJ to get some metrics in an existing application. When building and weaving with AJDT in eclipse, everything works fine. But into the integration of env. we use ant script to build and deploy the application.

The problem occurs in the ExceptionHandler, which I made to make sure that our aspect will not throw an exception and break the application

@Aspect public class ExceptionHandlerAspect { /** * Pointcut */ @Pointcut("within(com.xxx.yyy.aop.aspect.*..*)") public void allMethodInAspectPackage() {} /** * Pointcut */ @Pointcut("!within(com.xxx.yyy.aop.aspect.ExceptionHandlerAspect)") public void notInExceptionHandlerAspectClass() {} /** * Pointcut */ @Pointcut("call(* *(..))") public void allClassAndMethod() {} /** @Around("allClassAndMethod() && allMethodInAspectPackage() && notInExceptionHandlerAspectClass()") public Object logException(ProceedingJoinPoint joinPoint) throws Throwable{ Object ret = null; try { ret = joinPoint.proceed(); }catch (Throwable exception) { if (joinPoint.getSignature().getDeclaringTypeName().equalsIgnoreCase("org.aspectj.lang.ProceedingJoinPoint")) { throw exception; } this.logException.info("Exception in " + joinPoint.getSignature().getDeclaringTypeName(),exception); }finally { return ret; } } } 

Basically, I want to intercept every call in my package of aspects except ExceptionHandler itself.

The ant construction is as follows:

 <iajc inpath="${classes.dir}" destDir="${classes.dir}" fork="true" maxmem="${aspectj.maxmem}" verbose="true" showWeaveInfo="true" debug="true"> <classpath refid="ajclasspath"/> </iajc> 

$ {classes.dir} is the class directory in which the javac task created the application and aspects

From the result

 Exception in thread "main" java.lang.NoSuchMethodError: com.xxx.yyy.aop.aspect.ExceptionHandlerAspect.aspectOf()Lcom/xxx/yyy/aop/aspect/ExceptionHandlerAspect; at com.xxx.yyy.aop.aspect.ecs.AspectBaseEcs.inspectLoginInfo(AspectBaseEcs.java:65) at com.xxx.yyy.app.es.security.Security.loadApplications(Security.java:172) at com.xxx.yyy.app.es.gui.VSDlgLogin.loadSecurity(VSDlgLogin.java:346) at com.xx.yyy.app.es.ApplicationSuite.start(ApplicationSuite.java:839) at com.xxx.yyy.app.es.ApplicationSuite.main(ApplicationSuite.java:501) 

it looks like the ExceptionHandler was not gossip !!!

I hope someone can help me with this -)

+7
source share
3 answers

Finally found a problem. Our application depended on a common module that also contained an aspect.

The name of the base package was the same: com.xxx.aop , and the base class that we used for our aspects was with the same name. Thus, 2 com.xxx.aop.AspectBase.class were loaded.

Since we used the flag in our Ant build file to enable compile time during yes / no, one of our AspectBase.class not woven, and the other was.

+5
source

It looks like you forgot to declare the path aspect. Your whole task is to compile but not to bind. And this leads to java.lang.NoSuchMethodError

The following is an example showing how to use the iajc weaving task:

 <iajc outjar="demo.jar"> <sourceroots> <pathelement location="src" /> <pathelement location=".." /> </sourceroots> <aspectpath> <pathelement location="org.springframework.aspects-3.0.0.RC1.jar" /> </aspectpath> </iajc> 

Hope this helps!

0
source

I had a very similar problem

 java.lang.NoSuchMethodError: ....aspectOf()... 

I use Spring 3.1.2 + Maven 3.0.4 + Tomcat 7.0.29 and at different times it happens that when I start Tomcat, I get this exception.

I have no idea why this is happening. I use the Spring Tool ID IDE, but when I run mvn clean install from the command line (not in the IDE), it somehow fixes, maybe this helps someone.

0
source

All Articles