0
我正在尝试记录用自定义界面注释的方法的执行时间。用于内部和私有方法的AOP Java
我正在使用Spring AOP。
但是这似乎不适用于内部方法。
我认为这是在Spring AOP限制
@Aspect
public class BusinessProfiler {
private static Log log = LogFactory.getLog(BusinessProfiler.class);
@Around("execution(* *(..)) && @annotation(TimeLog)")
public Object profile(ProceedingJoinPoint point) throws Throwable {
long start = System.currentTimeMillis();
Object result = point.proceed();
String format =
String.format("%s#%s: took [%s msec]", point.getTarget().getClass().getSimpleName(),
MethodSignature.class.cast(point.getSignature()).getMethod().getName(),
System.currentTimeMillis() - start);
log.info(format);
return result;
}
}
是否有比Spring AOP
谢谢。有没有其他办法可以达到我的要求。我认为它与CDI相关。将CDI拦截器与Spring集成的任何选项 – Patan
此问题如何与CDI连接? CDI是关于依赖注入的,AOP是关于连接点截取的。如果你不愿意修改你的代码,并且需要捕获内部类,通过'this'调用方法(而不是通过外部代理)等等,你总是可以[在Spring中使用完整的AspectJ](https:// docs。 spring.io/spring/docs/current/spring-framework-reference/html/aop.html#aop-using-aspectj),甚至完全没有Spring。 – kriegaex