img
Table 7-1. Maven Dependencies for AspectJ
Group ID
Artifact ID
Version
Description
1.6.11
AspectJ runtime library
org.aspectj
aspectjrt
1.6.11
AspectJ weaving library
org.aspectj
aspectjweaver
Advanced Use of Pointcuts
In the previous chapter, we looked at six basic Pointcut implementations Spring provides; for the
most part, we found that these meet the needs of our applications. However, sometimes you need
more flexibility when defining pointcuts. Spring provides two additional Pointcut implementations,
ComposablePointcut and ControlFlowPointcut, that provide exactly the flexibility you need.
Use Control Flow Pointcuts
Spring control flow pointcuts, implemented by the ControlFlowPointcut class, are similar to the cflow
construct available in many other AOP implementations, although they are not quite as powerful.
Essentially, a control flow pointcut in Spring pointcuts all method calls below a given method or below
all methods in a class. This is quite hard to visualize and is better explained using an example.
Listing 7-1 shows a SimpleBeforeAdvice that writes a message out describing the method it is
advising.
Listing 7-1. The SimpleBeforeAdvice Class
package com.apress.prospring3.ch7.cflow;
import java.lang.reflect.Method;
import org.springframework.aop.MethodBeforeAdvice;
public class SimpleBeforeAdvice implements MethodBeforeAdvice {
public void before(Method method, Object[] args, Object target)
throws Throwable {
System.out.println("Before method: " + method);
}
}
This advice class allows us to see which methods are being pointcut by the ControlFlowPointcut. In
Listing 7-2, you can see a simple class with one method--the method that we want to advise.
Listing 7-2. The TestBean Class
package com.apress.prospring3.ch7.cflow;
public class TestBean {
public void foo() {
Search WWH :
Custom Search
Previous Page
Spring Framework 3 Topic Index
Next Page
Spring Framework 3 Bookmarks
Home