切点类型
- 切面类型
- 静态方法切点
- 动态方法切点
- 注解切点
- 表达式切点
- 流程切点
- 复合切点
切面类型
- 切面类型
- Advisor:一般切面
- PointcutAdvisor:具有切点的切面
- IntroductionAdvisor:引介切面
静态普通方法名匹配切面
publicclass Waiter {publicvoidgreetTo(String name){
System.out.println("waiter greet to " + name +"...");
}publicvoidservTo(String name){
System.out.println("waiter serving " + name +"...");
}
}
publicclass Seller {publicvoidgreetTo(String name){
System.out.println("seller greet to "+name+"...");
}
}
publicclassGreetingAdvisorextendsStaticMethodMatcherPointcutAdvisor {publicbooleanmatches(Method method, Class<?> aClass) {return"greetTo".equals(method.getName());
}public ClassFiltergetClassFilter(){returnnew ClassFilter(){publicbooleanmatches(Class<?> aClass) {return Waiter.class.isAssignableFrom(aClass);
}
};
}
}
publicclassGreetingBeforeAdviceimplementsMethodBeforeAdvice {publicvoidbefore(Method method, Object[] args, Object target)throws Throwable {
System.out.println(target.getClass().getName()+"."+method.getName());
String clientName = (String)args[0];
System.out.println("How are you!Mr."+clientName+".");
}
}
<beanid="waiterTarget"class="com.smart.advisor.Waiter"/>
<beanid="sellerTarget"class="com.smart.advisor.Seller"/>
<beanid="greetingAdvice"class="com.smart.advisor.GreetingBeforeAdvice"/>
<beanid="greetingAdvisor"class="com.smart.advisor.GreetingAdvisor"
p:advice-ref="greetingAdvice"/>
<beanid="parent" abstract="true"class="org.springframework.aop.framework.ProxyFactoryBean"
p:interceptorNames="greetingAdvisor"
p:proxyTargetClass="true"/>
<beanid="waiter" parent="parent" p:target-ref="waiterTarget"/>
<beanid="seller" parent="parent" p:target-ref="sellerTarget"/>
- StaticMethodMatcherPointcutAdvisor