读书人

spring札记

发布时间: 2012-08-26 16:48:06 作者: rapoo

spring笔记
常见Pointcout
1.NameMatchMethodPointcut

NameMatchMethodPointcut pointcut =new NameMatchMethodPointcut();pointcut.setMappedName("matches");//或多个方法pointcut.setMappedNames(new String[]{"matches","isRuntime"});

2.JdkRegexpMethodPointcut、Perl5RegexpMethodPointcut
JdkRegexpMethodPointcut pointcut=new JdkRegexpMethodPointcut();pointcut.setPattern(".*match.*");//或者pointcut.setPatterns(new String[](".*match.*",".*matches"});

3.AnnotationMatchingPointcut
@ClassLevelAnnotationpublic class GenericTargetObject{   @MethodLevelAnnotation   public void method1(){....};   public void method2(){....};}

只匹配Class
AnnotationMatchingPointcut pointcut=new AnnotationMatchingPointcut(   ClassLevelAnnotation.class);

或者用静态方法
AnnotationMatchingPointcut pointcut=AnnotationMatchingPointcut.forClassAnnotation(   ClassLevelAnnotation.class);

只匹配Method
AnnotationMatchingPointcut pointcut=new AnnotationMatchingPointcut(   MethodLevelAnnotation.class);

或者用静态方法
AnnotationMatchingPointcut pointcut=AnnotationMatchingPointcut.forMethodAnnotation(   MethodLevelAnnotation.class);


匹配Class及Method
AnnotationMatchingPointcut pointcut=new AnnotationMatchingPointcut(   ClassLevelAnnotation.class,MethodLevelAnnotation.class);

4.ComposablePointcut
5.定制Pointcut
继承StaticMethodMatcherPointcut
继承DynamicMethodMatcherPointcut




读书人网 >软件架构设计

热点推荐