Hello,
That's exactly what heppened - the advice got advised on. What I was trying to do was implementing a simple method level execution trace log. It turns out I have to use a pointcut expression something like: * (! package.aspectclass) *(..) to make it (or maybe a few "and" clauses)
Normally i would go to define my pointcuts in a logical way, then normally you will not get this problem. (Because in my projects i have my interceptors in other package then rest of the code).
For example i would have pointcuts like "withinserviceLayer" or "withinPresentation".
The Spring doc says that when using @AspectJ, the aspect class is automatically excluded from being advised. But I guess the schema-based AOP is a bit different (possibly with its reasons). The bottom line is, it feels like a little bit not intuitive and forcing the developer to know too much about the behind sciene implementation details of Spring AOP to use it.
I think Spring behavies like AspectJ, the only difference is the error message.
for testing with AspectJ i have changed your example a little bit
I have defined a new AspectJ pointcut that extends your Logger Aspect from your sample
Code:
package test;
public aspect LoggingAspect extends Logger {
pointcut logAllMethods() : execution( * *(..));
before() : logAllMethods() {
logBefore();
}
after() returning() : logAllMethods() {
logAfter();
}
}
After that i changed the main class, to use "pure" java
Code:
package test;
public class LoggerTarget {
public void doIt() {
System.out.println("do it!");
}
public static void main(String args[]) {
new LoggerTarget().doIt();
}
}
The result is an StackOverFlowerror
Code:
Exception in thread "main" java.lang.StackOverflowError
at test.Logger.logBefore(Logger.java:5)
at test.LoggingAspect.ajc$before$test_LoggingAspect$1$e68748f6(LoggingAspect.aj:9)
at test.Logger.logBefore(Logger.java:5)
..And around 300 line of the same stacktrace...
So also AspectJ don't prevent you to make such an error.
Best regards
agim