0
カスタムインターフェイスで注釈を付けたメソッドの実行時間を記録しようとしています。内部メソッドとプライベートメソッドのAOP Java
私はSpring AOPを使用しています。
しかし、これは内側のメソッドでは機能しないようです。
私はそれはあなたが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;
}
}
春AOP
ありがとうございます。私の要求を達成するための選択肢はありますか?私はそれがCDIでうまくいくと思います。 CDIインターセプタとSpringを統合するためのオプション – Patan
この問題はどのようにCDIに接続されますか? CDIは依存性注入に関するもので、AOPはjoinpointインターセプトに関するものです。コードを変更したくない場合や、内部クラスを取得する必要がある場合は、 'this'を使ってメソッド呼び出しを行います(外部からのプロキシ経由ではありません)、いつでも[Spring内のAspectJをフルに使うことができます](https:// docs。 spring.io/spring/docs/current/spring-framework-reference/html/aop.html#aop-using-aspectj)、またはSpringをまったく使用しなくても可能です。 – kriegaex