Home Tutorial Spring Spring3 Aop Control Flow Pointcut


Share on Google+Share on Google+
Control Flow Pointcut
Posted on: September 6, 2010 at 12:00 AM
In this tutorial you will learn about Spring AOP CotrolFlowPointcut.

Control Flow Pointcut Example

Spring AOP Control Flow Pointcut is Similar to AspectJ pointcut, but less powerful. It matches the current call stack. It can be implemented using org.springframework.aop.support.ControlFlowPointcut


package roseindia.net.coltrolFlowpointcut;

public class SimpleClass {
	public void sayHi() {
		System.out.println("Hello Friend");


package roseindia.net.coltrolFlowpointcut;

import java.lang.reflect.Method;

import org.aopalliance.intercept.MethodInterceptor;
import org.springframework.aop.MethodBeforeAdvice;

public class TestAdvice implements MethodBeforeAdvice {

	public void before(Method method, Object[] boObjects, Object object)
			throws Throwable {
		// TODO Auto-generated method stub
		System.out.println("Calling before " + method);



package roseindia.net.coltrolFlowpointcut;

import org.aopalliance.aop.Advice;
import org.springframework.aop.Advisor;
import org.springframework.aop.ClassFilter;
import org.springframework.aop.MethodMatcher;
import org.springframework.aop.Pointcut;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.aop.support.ControlFlowPointcut;
import org.springframework.aop.support.DefaultPointcutAdvisor;

public class TestControlFlow {
	public void test() {
		SimpleClass target = new SimpleClass();
		Pointcut pointcut = new ControlFlowPointcut(TestControlFlow.class,
		Advice advice = new TestAdvice();
		ProxyFactory proxyFactory = new ProxyFactory();

		Advisor advisor = new DefaultPointcutAdvisor(pointcut, advice);
		SimpleClass simpleProxy = (SimpleClass) proxyFactory.getProxy();
		System.out.println("Calling Normally");
		System.out.println("Calling in ControlFlow");

	public void controlFlowTest(SimpleClass simpleClass) {



package roseindia.net.coltrolFlowpointcut;

public class MainClaz {
	public static void main(String[] args) {
		TestControlFlow testControlFlow = new TestControlFlow();

When you run this application it will display message as shown below:

Calling Normally
Hello Friend
Calling in ControlFlow
Calling before public void roseindia.net.coltrolFlowpointcut.SimpleClass.sayHi()
Hello Friend

Download this example code


Related Tags for Control Flow Pointcut:

Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: September 6, 2010

Recommend the tutorial

Advertisements Advertisements