Home Tutorial Spring Spring3 Aop Spting AOP Static Pointcut


Share on Google+Share on Google+
Spting AOP Static Pointcut
Posted on: September 4, 2010 at 12:00 AM
In this example you will learn how use static pointcut of Spring AOP.

Static Pointcut

Static pointcuts are based on method and target class, they cannot take into account the methods arguments.


package roseindia.net.pointcut;

public class SimpleBean {
	public void greetMethod() {
		System.out.println("Have a Peaceful Day");


package roseindia.net.pointcut;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;

public class SimpleAdvice implements MethodInterceptor {

	public Object invoke(MethodInvocation methodInvocation) throws Throwable {
		// TODO Auto-generated method stub
		System.out.println("Calling " + methodInvocation.getMethod().getName());
		Object obj = methodInvocation.proceed();
		return obj;



package roseindia.net.pointcut;

import java.lang.reflect.*;

import org.springframework.aop.ClassFilter;
import org.springframework.aop.support.ClassFilters;
import org.springframework.aop.support.StaticMethodMatcherPointcut;

public class SimplePointCut extends StaticMethodMatcherPointcut {

	public boolean matches(Method method, Class clazz) {
		// TODO Auto-generated method stub
		return ("greetMethod".equals(method.getName()));



package roseindia.net.pointcut;

import java.lang.reflect.Proxy;

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.DefaultPointcutAdvisor;
import org.springframework.aop.support.Pointcuts;

public class TestPointCut {
	public static void main(String[] args) {
		SimpleBean simpleBean = new SimpleBean();
		SimpleBean beanProxy;
		Pointcut pointcut = new SimplePointCut();
		Advice advice = new SimpleAdvice();
		Advisor advisor = new DefaultPointcutAdvisor(pointcut, advice);

		ProxyFactory proxyFactory = new ProxyFactory();
		beanProxy = (SimpleBean) proxyFactory.getProxy();



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

Calling greetMethod
Have a Peaceful Day

Download this example code


Related Tags for Spting AOP Static 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 4, 2010

Recommend the tutorial

Advertisements Advertisements