我做了一个分析方法:在tld.mycompany.business.aspects.SystemArchitectureAspectJ的,一般不切入点构造
@Around("tld.mycompany.business.aspects.SystemArchitecture.inServiceLayer() && !tld.mycompany.business.aspects.SystemArchitecture.publicConstructor()")
public Object profileBusiness(ProceedingJoinPoint pjp) throws Throwable {
try {
long start = System.currentTimeMillis();
String name = pjp.getSourceLocation().toString() + " " + pjp.getSignature().getName();
Object output = pjp.proceed();
long elapsedTime = System.currentTimeMillis() - start;
if(elapsedTime > 100)
System.err.println("TimerAspect: Businessmethod " + name + " execution time: " + elapsedTime + " ms.");
return output;
} catch (Exception ex) {
ex.printStackTrace(System.err);
throw ex;
}
}
而定义的切入点为
@Pointcut("execution(public new(..))")
public void publicConstructor() {}
和
@Pointcut("within(tld.mycompany.business..*Impl) &&
!execution(private * tld.mycompany.business.*.dataType()) &&
!handler(java.lang.Exception)")
public void inServiceLayer() {}
我想剖析我的服务层中不是构造函数和异常的所有方法(所以t我没有得到“围绕初始化不支持(编译器限制)”和“围绕预初始化不支持(编译器限制)”警告)并忽略dataType(),我已经有几个。
但是,我仍然收到有关构造函数和异常的警告。它似乎也建议任何Java方法,所以调试我的应用程序几乎是不可能的,因为我为每一行都提供了很多建议。 Eclipse告诉我,它只有2747条针对profileBusiness系列的建议。
显然我一定误解了一些东西,但是什么?我怎样才能使它成为tld.mycompany.business层次结构中以Impl结尾的类中的所有方法(构造函数除外)?
干杯
聂
非常感谢,我没有发现内部和执行之间的区别。你会如何建议我将切入点写成你所建议的执行语句,但不包括构造函数? – niklassaers 2010-09-16 08:39:25
你可以使用'initialization(ConstructorPattern)'切入点。应该是这样的:'!初始化(*新(..))' – Thorben 2013-05-27 17:10:54