zoukankan      html  css  js  c++  java
  • 环绕通知@Around

    1.环绕通知需要在方法的参数中指定JoinPoint的子接口类型ProceedingJoinPoint为参数
      @Around(value="pointCut()")
      public void around(ProceedingJoinPoint joinPoint){
      }
     2.环绕通知会将其他4个通知能干的,自己都给干了!
      注意:@Around修饰的方法一定要将方法的返回值返回!本身相当于代理!
      
      @Around(value="pointCut()")
      public Object around(ProceedingJoinPoint joinPoint){
       Object[] args = joinPoint.getArgs();
       Signature signature = joinPoint.getSignature();
       String methodName = signature.getName();
       List<Object> list = Arrays.asList(args);
       Object result = null;
       try {
        //目标方法之前要执行的操作
        System.out.println("[环绕日志]"+methodName+"开始了,参数为:"+list);
        //调用目标方法
        result = joinPoint.proceed(args);
        //目标方法正常执行之后的操作
        System.out.println("[环绕日志]"+methodName+"返回了,返回值为:"+result);
       } catch (Throwable e) {
        //目标方法抛出异常信息之后的操作
        System.out.println("[环绕日志]"+methodName+"出异常了,异常对象为:"+e);
        throw new RuntimeException(e.getMessage());
       }finally{
        //方法最终结束时执行的操作!
        System.out.println("[环绕日志]"+methodName+"结束了!");
       }
       return result;
      }

  • 相关阅读:
    放假归来
    用ObjectSpaces重建IBuySpy的数据访问层
    在SPS中加入自定义WebService
    AnnouncementOSD.xml
    Delphi8 is out !
    ASP.NET PreCompilation and KeepAlive
    ScottGu回答了Whidbey发布的时间问题
    DiskBased Caching in Whidbey, Longhorn…
    AnnouncementRSD.xml
    忙着满足客户的需求...
  • 原文地址:https://www.cnblogs.com/Ysuwade/p/7449804.html
Copyright © 2011-2022 走看看