• 10. Spring 面向切面


    10.1 产品清单概述

    • 通知(Advice)
      • 前置通知(Before)
      • 后置通知(After)
      • 返回通知(After-returning)
      • 异常通知(After-throwing)
      • 环绕通知(Around)
    • 连接点(Join point)
    • 切点(Poincut)
    • 切面(Aspect)
    • 引入(Introduction)
    • 织入(Weaving)
      • 编译期
      • 类加载期
      • 运行期

    10.1 @Aspect定义切面、定义切入位置

    import org.aspectj.lang.annotation.*;
    
    @Aspect
    public class Notifier {
        @Before("execution(static void *..*.main(String[]))")
        public void before(){
            System.out.println("Application is running!");
        }
    
        @After("execution(static void *..*.main(String[]))")
        public void after(){
            System.out.println("execute end!");
        }
    
        @AfterReturning("execution(static void *..*.main(String[]))")
        public void afterReturning(){
            System.out.println("return end!");
        }
    
        @AfterThrowing("execution(static void *..*.main(String[]))")
        public void afterThrowing(){
            System.out.println("Exception");
        }
    }

    10.2 使用PointCup定义切入点、重复使用切入点

    import org.aspectj.lang.annotation.*;
    
    @Aspect
    public class Notifier {
    
        @Pointcut("execution(static void *..*.main(String[]))")
        public void pointCup(){}
    
        @Before("pointCup()")
        public void before(){
            System.out.println("Application is running!");
        }
    
        @After("pointCup()")
        public void after(){
            System.out.println("execute end!");
        }
    
        @AfterReturning("pointCup()")
        public void afterReturning(){
            System.out.println("return end!");
        }
    
        @AfterThrowing("pointCup()")
        public void afterThrowing(){
            System.out.println("Exception");
        }
    }
  • 相关阅读:
    vue.js环境的搭建
    图片上传简单demo及springboot上传图片
    mybatise 模糊查询
    thymeleaf th:onclick 传参
    thymeleaf的特殊属性赋值
    无限分类的设计及前后台代码
    mysql 多个属性排序查询
    java添加对象成功后想知道当前添加对象的id
    SpringBoot2.x集成MQTT实现消息推送
    linux下安装MQTT服务器
  • 原文地址:https://www.cnblogs.com/black-/p/9095797.html
Copyright © 2020-2023  润新知