FieldAccess Advice Example
using overloaded advices is more efficient than using nested if-else statements. JBoss AOP will call the correct advice version for each joinpoint type, avoiding the cost of checking the invocation type everytime this advice is invoked. This example could also be applied to another type of advice with minor changes: public void otherTypeOfAdvice(@JoinPoint ConstructorExecution joinPoint) { System.out.println(">>> otherTypeOfAdvice on constructor of class: " + joinPoint.getConstructor().getDeclaringClass().getName()); } public void otherTypeOfAdvice(@JoinPoint MethodExecution joinPoint) { System.out.println(">>> otherTypeOfAdvice on method execution: " + joinPoint.getAdvisedMethod().getName()); } public void otherTypeOfAdvice(@JoinPoint FieldAccess joinPoint) { System.out.println(">>> otherTypeOfAdvice on field" + (joinPoint.isRead()? "read: ": "write: ") + joinPoint.getAdvisedField().getName()); } ___________________________ Notice that FieldAccess is used for both field read and write joinpoints. The otherTypeOfAdvice advice is applied as a before advice in the example. However, it could have been applied as an after advice, or a finally advice. And it could also have been applied as an after-throwing advice if we added a @Thrown parameter to all overloaded versions of this advice. You can find the overloaded implementations of aroundAdvice and otherTypeOfAdvice in the JoinPointAspect.java file.