使用iajc构建时在运行时出现NoSuchMethodError AspectOf()
我们使用AspectJ来获取现有应用程序的一些指标.在Eclipse中使用AJDT进行构建和编织时,一切都很好.但是在整合环境中.我们使用ant脚本来构建和部署应用程序.
We used aspectJ to get some metric on an existing application. When building and weaving with AJDT in eclipse, everything works great. But in the integration env. we use an ant script to build and deploy the application.
为了确保我们的方面不会引发异常并破坏应用程序,我确实在ExceptionHandler上发生了问题
The problem occur on an ExceptionHandler i did to be sure our aspect would not throw 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;
}
}
}
基本上,我想拦截我的Aspects包中的每个调用,但ExceptionHandler本身除外.
Basicaly, i want to intercept every call within my aspects package except in the ExceptionHandler itself.
蚂蚁的身材看起来像这样:
the ant build look like this :
<iajc inpath="${classes.dir}" destDir="${classes.dir}" fork="true" maxmem="${aspectj.maxmem}" verbose="true" showWeaveInfo="true" debug="true">
<classpath refid="ajclasspath"/>
</iajc>
$ {classes.dir}是javac任务在其中构建应用程序和方面的classes目录.
The ${classes.dir} is the classes directory where the javac task built the application and the aspects
从结果
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)
好像没有编织ExceptionHandler !!!
it looks like the ExceptionHandler was not weaved!!!
我希望有人可以在这方面帮助我;-)
I hope someone can help me on this one ;-)
终于找到了问题所在.我们的应用程序也依赖于也包含方面的通用模块jar.
Finally found the problem. Our Application had a dependency on common module jar that was containing aspect too.
基本包名称是相同的:com.xxx.aop
和我们用于各方面的基本类是相同的名称.因此,已加载2个com.xxx.aop.AspectBase.class
.
The base package name was the same: com.xxx.aop
and the base class we used for our aspects was the same name. So 2 com.xxx.aop.AspectBase.class
were loaded.
由于我们在Ant生成文件中使用了一个标志,以使编译时的编织结果是/否,所以我们其中一个AspectBase.class
未被编织,而另一个则被编织.
Since we used a flag in our Ant build file to enable compile time weaving at yes/no, one of our AspectBase.class
was not weaved while the other was.