Skip to content
tylertreat edited this page Jan 21, 2013 · 3 revisions

The After annotation indicates that the annotated advice method in an Aspect class is to be executed after a join point is invoked. The join point itself will be passed as an argument to methods annotated with this.

Annotation Attributes

After 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 @After(beans = "myBean").

To apply the advice to all methods named foo in myBean, the method name is specified with a wildcard (*) character, e.g. @After(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 @After(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 @After(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.

After Example

The example below illustrates how an after advice method can be specified using the After annotation.

@After(beans = { "fooBean", "barBean.foo(*)", "barBean.bar(java.util.Date)" }, within = "com.foo.bar", order = 1)
public void afterAdvice(JoinPoint joinPoint) {
    // ...
}
Clone this wiki locally