AOP Bean Pointcut
•        In Spring 2.0, annotations were introduced to greatly simplify the configuration of aspects.
•        In Spring 2.0, an aspect is made from any class using the @Aspect annotation.
•        Pointcuts designators are then used to indicate when/were the advice of an aspect was triggered.
•        In the example below, an execution designator is used to signal that the advice should trigger for any
method of any class in the package.
@Aspect
public class MyAspect {
@Before("execution(* "com.intertech.dao.*.(..))")
public void doSomething() {
...
•        In Spring 2.0, there are nine (9) types of pointcut discriminators (see table below.
execution
within
target
this
args
@within
@annotation
@target
@args
•        In Spring 2.5, an additional pointcut discriminator, bean, was added.

•        The bean pointcut discriminator allows advice to be targeted based on the name or id of a bean.
@Aspect
public class MyAspect {
@Before("bean(orderDao)")
public void countAccess() {
System.out.println("Database accessed at:" + System.currentTimeMillis());
...
}
...
•        In this example, the countAccess advice is triggered before any OrderDao bean’s method is invoked.
•        The wild card character (‘*’) can be used to specify a collection of beans in the pointcut.
@Before("bean(order*)")
public void countAccess() {
System.out.println("Database accessed at:" + System.currentTimeMillis());
...
}
•        In this example, beans with a name beginning with “order” will trigger the advice.
•        The bean pointcut is only supported by Spring AOP and not AspectJ implementations.

•        Another AOP addition in Spring 2.5 is the support for load-time weaving of aspects into Spring classes.
•        In Load-time weaving, advice is added or “woven” into the actual class affected by aspects when the
class file is loaded.
•        This is an alternate approach to the current proxy based mechanism in place for AOP within Spring 2.0
(and before).
•        In this approach, the JVM’s ClassLoader must be adapted to transform the classes as they are loaded
into memory.
•        Load-time weaving is only available when using AspectJ AOP.
•        Load-time weaving should offer better performance than proxy-based weaving of aspects.
•        Complete coverage of load-time weaving is beyond the scope of this update.
AOP Bean Pointcut
Table of Contents
Copyright (c) 2008.  Intertech, Inc. All Rights Reserved.  This information is to be used exclusively as an
online learning aid.  Any attempts to copy, reproduce, or use for training is strictly prohibited.
Courseware
Training Resources
Tutorials