• 用注解配置动态代理


    /**
    * 切面类,要将当前类中的方法插入到目标对象的方法
    *
    * @author ASUS
    *
    */
    @Aspect
    // 表示此类为切面类
    public class ProxyObj {
    // // @Before 表示前置通知。目标方法执行前需要调用该方法
    // // * com.lovo.service.*.*(..) 表示目标方法的路径
    // // 第一个*表示方法返回类型为任意类型
    // // com.lovo.service为包名 com.lovo.service..为指定包和指定的子包
    // // *.*表示该包中所有的类的所有的方法 s*.*表示该包中以s开头的类的所有的方法
    // // (..)该方法中的参数为任意参数
    // // @Before("execution(* com.lovo.service.*.*(..))")
    // // public void ready() {
    // // System.out.println("开始订餐。。。");
    // // }
    // // @AfterReturning("execution(* com.lovo.service.*.*(..))")
    // // public void end(){
    // // System.out.println("开发票。。");
    // // }
    // // 环绕注解
    // @Around("execution(* com.lovo.service.*.*(..))")
    // public Object around(ProceedingJoinPoint point) {
    // System.out.println("取钱");
    // try {
    // // 执行目标方法,该方法将得到目标方法执行完毕后的返回值
    // Object value = point.proceed();
    // System.out.println("茶多酚");
    // return value;
    // } catch (Throwable e) {
    // // TODO Auto-generated catch block
    // e.printStackTrace();
    // }
    // return null;
    // }

    @AfterThrowing(value = "execution(* com.lovo.service.*.*(..))", throwing = "er")
    public void throwsMethod(JoinPoint point, Exception er) {
    // 得到目标对象
    Object obj = point.getTarget();
    // 得到目标对象的类型
    String className = obj.getClass().getName();
    // 得到目标方法名
    String methodName = point.getSignature().getName();
    System.out.println("执行"+className+"的"+methodName+"方法,抛出"+er.getMessage());
    }

    }

  • 相关阅读:
    centos8 防火墙配置增加端口
    linux上搭建maven私服(下)
    linux上搭建maven私服(中)
    项目成本管理中的PV、EV与AC的区别-实例解释
    配置IKE SA的生存周期(华为)
    IKE SA和IPSec SA的区别
    IPsecVPN协商过程-主模式
    Fortigate防火墙常用命令
    飞塔防火墙清除系统密码
    fatal: unable to access ‘https://github xxxxxxxxx的解决方法
  • 原文地址:https://www.cnblogs.com/sanhuan/p/4029810.html
Copyright © 2020-2023  润新知