aop切入点表达式
来源:互联网 发布:淘宝店女装推荐 编辑:程序博客网 时间:2024/04/29 01:09
1、切入点表达式的格式:execution([可见性] 返回类型 [声明类型].方法名(参数) [异常])
2、切入点表达式通配符:
*:匹配所有字符
..:一般用于匹配多个包,多个参数
+:表示类及其子类
3、切入点表达式支持逻辑运算符:&&、||、!
4、切入点表达式关键词:
1)execution:用于匹配子表达式。
//匹配com.cjm.model包及其子包中所有类中的所有方法,返回类型任意,方法参数任意
@Pointcut("execution(* com.cjm.model..*.*(..))")
public void before(){}
2)within:用于匹配连接点所在的Java类或者包。
//匹配Person类中的所有方法
@Pointcut("within(com.cjm.model.Person)")
public void before(){}
//匹配com.cjm包及其子包中所有类中的所有方法
@Pointcut("within(com.cjm..*)")
public void before(){}
3) this:用于向通知方法中传入代理对象的引用。
@Before("before() && this(proxy)")
public void beforeAdvide(JoinPoint point, Object proxy){
//处理逻辑
}
4)target:用于向通知方法中传入目标对象的引用。
@Before("before() && target(target)
public void beforeAdvide(JoinPoint point, Object proxy){
//处理逻辑
}
5)args:用于将参数传入到通知方法中。
@Before("before() && args(age,username)")
public void beforeAdvide(JoinPoint point, int age, String username){
//处理逻辑
}
6)@within:用于匹配在类一级使用了参数确定的注解的类,其所有方法都将被匹配。
@Pointcut("@within(com.cjm.annotation.AdviceAnnotation)") - 所有被@AdviceAnnotation标注的类都将匹配
public void before(){}
- @Retention(RetentionPolicy.RUNTIME)
- @Target({ElementType.TYPE, ElementType.METHOD})
- @Documented
- @Inherited
- public @interface AdviceAnnotation {
- }
7)@target:和@within的功能类似,但必须要指定注解接口的保留策略为RUNTIME。
@Pointcut("@target(com.cjm.annotation.AdviceAnnotation)")
public void before(){}
8)@args:传入连接点的对象对应的Java类必须被@args指定的Annotation注解标注。
@Before("@args(com.cjm.annotation.AdviceAnnotation)")
public void beforeAdvide(JoinPoint point){
//处理逻辑
}
- public class Person {
- public void say(Address address){
- //处理逻辑
- }
- }
- @AdviceAnnotation
- public class Address {
- }
如果需要在Person类的say方法被调用时触发beforeAdvide通知,那么say方法的参数对应的Java类型Address类必须要被@AdviceAnnotation标注。
9)@annotation:匹配连接点被它参数指定的Annotation注解的方法。也就是说,所有被指定注解标注的方法都将匹配。
@Pointcut("@annotation(com.cjm.annotation.AdviceAnnotation)")
public void before(){}
- public class Person {
- @AdviceAnnotation
- public void say(Address address){
- //处理逻辑
- }
- }
Person类的say方法被@AdviceAnnotation标注,所以它匹配。
10)bean:通过受管Bean的名字来限定连接点所在的Bean。该关键词是Spring2.5新增的。
@Pointcut("bean(person)")
public void before(){}
id为person的受管Bean中的所有方法都将匹配。
- aop切入点表达式
- aop切入点表达式
- AOP切入点表达式写法
- aop切入点表达式
- Spring AOP切入点表达式
- Spring AOP 切入点表达式
- aop 切入点表达式示例
- AOP切入点表达式解析
- Aop切入点的表达式
- aop切入点表达式
- AOP切入点表达式语法
- Spring AOP execution 切入点表达式
- Spring AOP execution 切入点表达式
- Spring Aop 切入点表达式解析
- Spring AOP 切入点表达式使用
- Spring AOP 切入点常用表达式
- spring AOP切入点表达式规则
- Spring Aop配置时的切入点表达式
- hibernate连接池配置
- C#基础
- Python与C之间的相互调用(Python C API及Python ctypes库)
- py正则表达式
- oracle临时表
- aop切入点表达式
- 怎样看待大学期间的代码练习
- DataTable中的增删改查
- oracle特殊的表dual
- 961冠号之谜
- HVM(硬件辅助虚拟化)技术
- 使用opensuse 11.4 Blogilo 发的一篇 blog
- perl 字符加减
- oracle表操作语句