Spring AOP

Pointcut匹配条件

Advice匹配后执行操作 

/**
 * //匹配任何公共方法
 *
 * @Pointcut("execution(public * com.imooc.service.*.*(..))")
 *         <p>
 *         //匹配com.imooc包及子包下Service类中无参方法
 * @Pointcut("execution(* com.imooc..*Service.*())")
 *         <p>
 *         //匹配com.imooc包及子包下Service类中的任何只有一个参数的方法
 * @Pointcut("execution(* com.imooc..*Service.*(*))")
 *         <p>
 *         //匹配com.imooc包及子包下任何类的任何方法
 * @Pointcut("execution(* com.imooc..*.*(..))")
 *         <p>
 *         //匹配com.imooc包及子包下返回值为String的任何方法
 * @Pointcut("execution(String com.imooc..*.*(..))")
 *         <p>
 *         //匹配异常
 *         execution(public * com.imooc.service.*.*(..) throws java.lang.IllegalAccessException)
 *         <p>
 *         Created by cat on 2017-02-19.
 */
@Aspect
@Component
public class ExecutionAspectConfig {
    // Pointcut匹配条件
    @Pointcut("execution(public * com.imooc.service..*Service.*(..) throws java.lang.IllegalAccessException)")
    public void matchCondition() {
    }
    // 匹配后执行策略
    @Before("matchCondition()")
    public void before() {
        System.out.println("");
        System.out.println("###before");
    }

}

 

  

/**
 * //匹配AOP对象的目标对象为指定类型的方法,即LogService的aop代理对象的方法
 * @Pointcut("this(com.imooc.log.Loggable)")
 * //匹配实现Loggable接口的目标对象(而不是aop代理后的对象)的方法
 * @Pointcut("target(com.imooc.log.Loggable)")
 * //this 可以拦截 DeclareParents(
 * Introduction)
 * //target 不拦截 DeclareParents(Introduction)
 * //匹配所有以Service结尾的bean里头的方法
 * @Pointcut("bean(*Service)")
 * Created by cat on 2016-12-04.
 */

introduction

 

 

 

 execution

修饰符

返回类型

包名

描述方法名(描述方法参数)

抛出异常类型

?表示可以省略

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值