execution() ポイントカットのみを理解するため、Spring AOP は役に立ちません。
AspectJ には、あなたが望むもののように聞こえる withincode() コンストラクトを含む、より多くのポイントカットが含まれています。
withincode(* YourClass.methodX(. .))
これにより、特定のメソッド実行内のすべての結合ポイントをアドバイスできます
詳細については、 AspectJ in Actionを参照してください。これは、AspectJ と Spring AOP の両方に関する非常に優れた本です。
編集:
ここにいくつかのサンプルコードがあります:
package com.dummy.aspectj;
import java.util.Arrays;
import java.util.Collections;
public class DummyClass{
public static void main(final String[] args){
System.out.println(Arrays.asList("One", Collections.singleton("Two")));
System.out.println("Enough?");
}
}
package com.dummy.aspectj;
import java.util.Arrays;
public aspect DummyAspect{
pointcut callWithinMain() :
withincode(* com.dummy.aspectj.DummyClass.main(..)) // anything inside DummyClass.main
&& call(* *.*(..)); // but only method calls
before() : callWithinMain() {
System.out.println("\n***************************************************");
System.out.println("** Calling:\n**\t"
+ thisJoinPointStaticPart.getSignature()
+ "\n** with arguments:\n**\t "
+ Arrays.deepToString(thisJoinPoint.getArgs()) );
System.out.println("***************************************************\n");
}
}
Eclipse / AJDT から DummyClass を実行すると、次の出力が生成されます。
***************************************************
** Calling:
** Set java.util.Collections.singleton(Object)
** with arguments:
** [Two]
***************************************************
***************************************************
** Calling:
** List java.util.Arrays.asList(Object[])
** with arguments:
** [[One, [Two]]]
***************************************************
***************************************************
** Calling:
** void java.io.PrintStream.println(Object)
** with arguments:
** [[One, [Two]]]
***************************************************
[One, [Two]]
***************************************************
** Calling:
** void java.io.PrintStream.println(String)
** with arguments:
** [Enough?]
***************************************************
Enough?