Aspect oriented programming is used when some action should be performed at specific moment of the program, but do not influence the way of running of the program. The typical examples is logging, caching, history, timing, authentication...
There is a number of new concept to learn: crosscutting concern, join point, point cuts, advice.
- a join point is a point of the execution of the program
- a point cut is a way of selecting join points in the program
- an advice is the code to be executed when reaching the point cut
Note the keyword aspect, as well as before() ... the advice is:public aspect TraceAspect { pointcut trace () : call (* * (..)) && ! within(TraceAspect); before() : trace() { System.out.println("ADV:"+thisJoinPoint.getSignature()); } }
System.out.println("ADV:"+thisJoinPoint.getSignature());and is called before a method when not within( TraceAspect) Since there are already many aspect oriented programming with the spring framework, it might be prefarable to use that.