I tried to define a pointcut which would match all methods in a class, but it did not work. I tried hard to find out the reason why. And I eventually found the fault point of the pointcut expression I defined.
The following is the beginning of what I defined first. (does not work)
@Pointcut("execution(** membership.data.MemberRepository.*(..))")
As I had known, the consecutive two asterisks in "execution(**" means any access modifier and any return type, but It never matched some methods that has some kind of return types like this :
public List<MemberVO> findByName(String name) { ...
On the other hand, It matched another like this:
public String print(String str) { ...
And the following is the begining of the proper ways of defining it which I found out. these match the above two method signatures and work fine.
@Pointcut("execution(public * membership.data.MemberRepository.*(..))")
@Pointcut("execution(* membership.data.MemberRepository.*(..))")
What was I missing? I tried hard to find the answer but it never appeared. Please let me know the exact meaning of "execution(** ".
Addition: The full source of the aspect class
@Aspect
public class PerformanceLogger {
@Pointcut("execution(* membership.data.MemberRepository.*(..))")
public void performance() {}
@Around("performance()")
public Object watchPerformance(ProceedingJoinPoint jp) {
try {
long st = System.nanoTime();
Object obj = jp.proceed();
System.out.println(jp.toShortString() + " called :" + (System.nanoTime() - st));
return obj;
} catch (Throwable e) {
throw new RuntimeException(e);
}
}
}
As I said in my comment: **
does not mean anything, you are lucky the parser seems to interpret it as equivalent to *
, but you cannot be sure. Actually it should yield a syntax error. So please do not use it, it is meaningless. Your assumption about the meaning is just false. * * blah(..)
also does not work, it is invalid syntax. IMO it should be fixed in the book "Spring in Action", I also found it there. In the whole AspectJ documentation you will not find something like **
.
As for your question: In order to get all method executions for class membership.data.MemberRepository
you use the pointcut execution(* membership.data.MemberRepository.*(..))
. You already found out by yourself.