Default Pointcut Advisor : Pointcut « Spring « Java Tutorial






File: Main.java

import org.springframework.aop.Advisor;
import org.springframework.aop.aspectj.AspectJExpressionPointcut;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.aop.support.DefaultPointcutAdvisor;

import bean.MyClass;
import bean.SimpleAfterAdvice;

public class Main {

  public static void main(String[] args) {
    MyClass target = new MyClass();

    AspectJExpressionPointcut pc = new AspectJExpressionPointcut();
    pc.setExpression("execution(* bean..*.get*(..))");

    Advisor advisor = new DefaultPointcutAdvisor(pc, new SimpleAfterAdvice());

    ProxyFactory pf = new ProxyFactory();
    pf.setTarget(target);
    pf.addAdvisor(advisor);

    MyClass proxy = (MyClass) pf.getProxy();
    System.out.println(proxy.getName());
    proxy.setName("New Name");
    System.out.println(proxy.getHeight());

  }

}

File: MyClass.java

package bean;


public class MyClass {

    public String getName() {
        return "AAA";
    }

    public void setName(String name) {

    }

    public int getHeight() {
        return 201;
    }
}

File: SimpleAfterAdvice.java

package bean;

import org.springframework.aop.AfterReturningAdvice;

import java.lang.reflect.Method;


public class SimpleAfterAdvice implements AfterReturningAdvice{
    public void afterReturning(Object returnValue, Method method, Object[] args, Object target) throws Throwable {
        System.out.println("After method: " + method);
    }
}
  Download:  Spring-DefaultPointcutAdvisor.zip( 4,746 k)








28.56.Pointcut
28.56.1.Default Pointcut Advisor
28.56.2.Control Flow Pointcut
28.56.3.ComposablePointcut Union
28.56.4.ComposablePointcut Intersection
28.56.5.Class Filter In DynamicMethodMatcherPointcut
28.56.6.NameMatchMethodPointcutAdvisor
28.56.7.NameMatchMethodPointcut
28.56.8.Jdk Regexp based Method Pointcut
28.56.9.All Kinds Of Pointcut