In the previous post we have seen how to use a advice. But the problem with the example
given in the previous post is that, the advice will run for any method which matches the
criteria. In other words, the execution criteria given is generic and it is not specific
to a particular method. Below are some of the execution criteria's which can be applied
to advises.
@Before("execution(public String com.ram.model.Circle.getName())") public void LoggingAdvice(){ ... }
The below code is an example of wildcard expression for the advice. It says that the
advice should be run for all methods which are public and whose return type could be
anything even void and whose method names start with 'get'.
@Before("execution(public * get*())") public void LoggingAdvice(){ ... }
The below code is an another example of wildcard expression for the advice. It says that the
advice should be run for all methods whose access modifier could be anything, whose return type
could be anything, whose name start with 'get' and which will take zero or more parameters. The
'..' indicate that the method can take zero or more parameters.
@Before("execution(* get*(..))") public void LoggingAdvice(){ ... }
No comments:
Post a Comment