Repository navigation
Around
The Around annotation indicates that the annotated advice method in an Aspect class is to be executed around a join point. A specialized join point called ProceedingJoinPoint will be passed as an argument to methods annotated with this.
Around advice has the ability to prevent a join point from being executed by returning its own return value, throwing an exception, or simply not invoking ProceedingJoinPoint.proceed().
Around has three attributes that can be used to specify advice metadata.
beans: declares the beans and, optionally, specific methods which make up a pointcut (i.e. where the annotated advice should be invoked with regard to specific beans) as an array.
A simple example that would apply the advice to a single bean named myBean would be @Around(beans = "myBean").
To apply the advice to all methods named foo in myBean, the method name is specified with a wildcard (*) character, e.g. @Around(beans = "myBean.foo(*)").
To apply the advice to a specific method foo in myBean which takes an integer and float as arguments, it would look like @Around(beans = "myBean.foo(java.lang.Integer, java.lang.Float)").
within: declares the packages such that any contained type's methods make up a pointcut (i.e. where the annotated advice should be invoked with regard to specific packages) as an array.
A simple example that would apply the advice to every method of every bean in the package com.foo.bar would be @Around(within = "com.foo.bar").
order: Declares the advice precedence. A smaller number indicates a higher precedence, while a larger number indicates a lower precedence. The default value is Integer.MAX_VALUE. The precedence determines the order in which advice is executed.
The example below illustrates how an around advice method can be specified using the Around annotation.
@Around(beans = { "fooBean", "barBean.foo(*)", "barBean.bar(java.util.Date)" }, within = "com.foo.bar", order = 1)
public Object aroundAdvice(ProceedingJoinPoint joinPoint) throws Exception {
// ...
Object result = joinPoint.proceed();
// ...
return result;
}