首页 > 编程语言 > 详细

spring学习第7天(PCD以及切点表达式)

时间:2019-10-28 14:13:21      阅读:105      评论:0      收藏:0      [点我收藏+]

1.PCD(PointCutDesigner)

spring的aop只针对方法进行aop代理,而apectj联盟的aop比之更加强大,还可以针对字段等进行切面编程

 1.1:execution,用的最多的,用来匹配连接点方法

 1.2:within:翻译是“在内部”,对某个/些类下的所有方法进行代理

 1.3:this:确定动态代理之后的是某个类型

 1.4:target:指明被代理的对象类型

 1.5:args:指定方法的参数类型,例args(Integer,String)

 1.6:@target:目标类型上有特定注解修饰

 1.7:@args:表明参数上有特定注解修饰

 1.8:@within:表明类上有特定注解修饰

 1.9:@annotation:连接点方法上有特定的注解修饰

 1.10:bean:spring aop提供的,指定有特定bean名字的

2.指示器的逻辑运算符:and(代替&&),or(代替||),not(代替!)

3.execution:编写格式为:

execution(modifiers-pattern? ret-type-pattern declaring-type-pattern?name-pattern(param-pattern)throws-pattern?)

其中ret-type-pattern,name-pattern(param-pattern)这三个是必写的

?表示可选

modifiers-pattern:修饰符模式,可选

ret-type-pattern:返回类型模式,必写

declaring-type-pattern:声明类型模式,即包名和类名,之间用“.”表示什么什么下的什么,可选

name-pattern:方法名字模式,必写

param-pattern:参数模式,方法参数,必写

throws-pattern:异常模式,可选,格式为:throws 异常

通配符:*:表示任意名字  ..:任意段任意字符,比如com.service.impl包可以直接写成com.*.*或者com..即可

一些常见的例子:

 1:execution(public * *(..))                所有的公有方法

 2:execution(* get*(..))         任意以get开头的方法

 3:execution(* com.service.impl.DeptService+)         表示接口的所有方法以及实现了该接口的所有方法都被aop代理

 4:execution(* com..*(..))            com包下的以及com子包下的所有方法

 

spring学习第7天(PCD以及切点表达式)

原文:https://www.cnblogs.com/woyujiezhen/p/11751520.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!