spring学习(二 )aop

spring中基于aop的配置步骤

1.把通知bean交给spring管理
2.使用aop:config标签开始aop配置
3,使用aspect配置切面(id标志 ref通知类bean的id)
4.在aspect内部使用对应标签来配置通知类型(AOP:before method)
5.pointcut表示指定切入点表达式
写法:
关键字:execution
表达式:
访问修饰符 包明。。。类名。方法名
public void com.spring_learn,.....
全通配写法:* *..*.*(..)
实际写法:*(包名).*.*(..)
  • 通知的其他几种类型
    前置,后置,异常,最终。。。

  • 切入点

<aop:pointcut id="..." expression="execution(....)"></aop:pointcut>
<aop:aspect id="" ref="...">
<aop:before method="" pointcut-ref=""></aop:before>
</aop:aspect>

环绕

 public Object aroundprintLog(ProceedingJoinPoint pjp)
    {
        Object rvalue = null;
        try {
            Object[] args = pjp.getArgs();
            System.out.println("前置");
            rvalue = pjp.proceed(args);//切入点方法
            System.out.println("后置");
            return rvalue;
        }catch (Throwable t)
        {
         System.out.println("异常");
         throw new RuntimeException(t);
        }finally {
    System.out.println("最终");
        }


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值