2、AOP

作者: lois想当大佬 | 来源:发表于2019-12-10 13:56 被阅读0次

1、什么是AOP
把遍布应用各处的功能分离出来形成可重用的组件。Eg: 事务、日志、安全。

2、aop术语
切面(aspect):切点与通知的结合。
切点(pointcut):定义了切面何处执行。
连接点(joinpoint):能够插入切面的一个点,为应用添加新行为。一个切点包含多个连接点。
通知(advice):定义了切面是什么以及何时使用。5种类型的通知:before、after、after-returning、after-throwing、around。
织入(weaving):spring aop是运行期织入。把通知绑定到目标对象连接点上的过程称为织入。

3、AOP的2种实现方式
xml: <aop:config></aop:config>
注解:

@Aspect
@Component
public class Audience {

   @Pointcut("execution(* service.Performance.perform(int)) && args(num)")
   public void performance(int num) {};

   @Before("performance()")
   public void takeSeats() {
       System.out.println("take seats");
   }

   @After("performance()")
   public void applause() {
       System.out.println("ha ha ha ha");
   }

   @AfterThrowing("performance()")
   public void demandRefund() {
       System.out.println("demand refund");
   }

   @Around("performance()")
   public void watchPerform(ProceedingJoinPoint jp) {
       try {
           System.out.println("silence cell phones");
           System.out.println("take seats");
           jp.proceed();
           System.out.println("ha ha ha ha");
       } catch (Throwable e) {
           System.out.println("demand refund");
       }
   }

   private int count = 0;
   @Before("performance(num)")
   public void silenceCellPhones(int num) {
       System.out.println("silence cell phones");
       System.out.println("num = " + num + " count = " + (++count));
   }
}

相关文章

  • spring-aop

    aop概念aop概念aop术语AOP实现方式1、spring-aop(使用xml文件实现AOP)2、AspectJ...

  • Spring AOP-基础使用

    零、本文纲要 一、了解AOP1、认识AOP2、AOP作用3、AOP核心概念 二、AOP快速入门1、基础准备2、AO...

  • SpringBoot开发随记--AOP的使用

    SpringBoot开发随记--AOP的使用 Aop原理 1、什么是Aop2、Aop常用术语3、AOP表达式4、A...

  • Spring框架AOP源码分析(二)

    AOP编程使用 1.注解版本实现AOP 2.XML方式实现AOP Xml实现aop编程:1) 引入jar文件 【...

  • Spring_AOP笔记

    **** AOP 面向切面编程 底层原理 代理!!! 今天AOP课程1、 Spring 传统 AOP2、 Spri...

  • AOP

    java创建对象的方法(5种): Spring AOP: spring分为: 1、IOC/DI 2、AOP AOP...

  • Spring AOP源码解析

    0.AOP整体流程 1)@EnableAspectJAutoProxy 开启AOP功能2)@EnableAspec...

  • Spring4.x学习笔记(二)

    1.AOP的底层实现原理:image.pngimage.png 2.AOP操作术语:image.png 3.AOP...

  • SSH框架之旅-struts2(4)

    1.Struts2 拦截器 1.1 AOP 思想 AOP 是 Aspect Objected Prograing(...

  • AOP原理总结

    AOP原理总结: 1) @EnableAspectJAutoProxy 利用这个注解开启AOP功能 2) @Ena...

网友评论

      本文标题:2、AOP

      本文链接:https://www.haomeiwen.com/subject/avqggctx.html