1、Spring4、SpringBoot1

  1.1 代码实现

public interface Calculator {

    int div(int a,int b);
}
@Component
public class CalculatorImpl implements Calculator{
@Override
public int div(int a, int b) {
int result = a/b;
System.out.println("计算结果为:"+result);
return result;
}
}
@Aspect
@Component
public class CalculatorAspect {
@Before(value = "execution(* com.jixian.springboot1.CalculatorImpl.*(..))")
public void beforeNotify(){
System.out.println("@Before...前置通知");
}
@After(value = "execution(* com.jixian.springboot1.CalculatorImpl.*(..))")
public void afterNotify(){
System.out.println("@After...后置通知");
}
@AfterReturning(value = "execution(* com.jixian.springboot1.CalculatorImpl.*(..))")
public void afterReturningNotify(){
System.out.println("@AfterReturning...返回通知");
}
@AfterThrowing(value = "execution(* com.jixian.springboot1.CalculatorImpl.*(..))")
public void afterThrowingNotify(){
System.out.println("@AfterThrowing...异常通知");
}
@Around(value = "execution(* com.jixian.springboot1.CalculatorImpl.*(..))")
public Object aroundNotify(ProceedingJoinPoint joinPoint) throws Throwable{
Object res = null;
System.out.println("@Around...环绕通知之前A");
res = joinPoint.proceed();
System.out.println("@Around...环绕通知之后B");
return res;
}
}

  1.2 测试

@SpringBootTest
@RunWith(SpringRunner.class)
public class SpringBoot1ApplicationTests {
@Autowired
private Calculator calculator; @Test
public void contextLoads() {
System.out.println("Spring版本:"+ SpringVersion.getVersion()+"\t"+"SpringBoot版本:"+ SpringBootVersion.getVersion());
calculator.div(5,2);
} }

2、Spring5、SpringBoot2

3、Spring6、SpringBoot3

Spring不同版本的AOP的更多相关文章

  1. spring之初识Ioc&Aop

    Spring框架的作用 spring是一个轻量级的企业级框架,提供了ioc容器.Aop实现.dao/orm支持.web集成等功能,目标是使现有的java EE技术更易用,并促进良好的编程习惯. Spr ...

  2. 转:Spring历史版本变迁和如今的生态帝国

    Spring历史版本变迁和如今的生态帝国     版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/bntX2jSQfEHy7/article/deta ...

  3. Spring 使用xml配置aop

    1.xml文件需要引入aop命名空间 2.xml内容: <?xml version="1.0" encoding="UTF-8"?> <bea ...

  4. Spring MVC 中使用AOP 进行统一日志管理--注解实现

    1.AOP简介 AOP称为面向切面编程 AOP的基本概念 (1)Aspect(切面):通常是一个类,里面可以定义切入点和通知 (2)JointPoint(连接点):程序执行过程中明确的点,一般是方法的 ...

  5. [转]Spring历史版本变迁和如今的生态帝国

    前两篇: 为什么要有Spring? 为什么要有Spring AOP? 前两篇从Web开发史的角度介绍了我们在开发的时候遇到的一个个坑,然后一步步衍生出Spring Ioc和Spring AOP的概念雏 ...

  6. -手写Spring注解版本&事务传播行为

    视频参考C:\Users\Administrator\Desktop\蚂蚁3期\[www.zxit8.com] 0018-(每特教育&每特学院&蚂蚁课堂)-3期-源码分析-手写Spri ...

  7. spring boot: filter/interceptor/aop在获取request/method参数上的区别(spring boot 2.3.1)

    一,filter/interceptor/aop在获取参数上有什么区别? 1,filter可以修改HttpServletRequest的参数(doFilter方法的功能), interceptor/a ...

  8. Spring的IOC和AOP之深剖

    今天,既然讲到了Spring 的IOC和AOP,我们就必须要知道 Spring主要是两件事: 1.开发Bean:2.配置Bean.对于Spring框架来说,它要做的,就是根据配置文件来创建bean实例 ...

  9. Spring(6)—— AOP

    AOP(Aspect-OrientedProgramming)面向切面编程,与OOP完全不同,使用AOP编程系统被分为切面或关注点,而不是OOP中的对象. AOP的引入 在OOP面向对象的使用中,无可 ...

  10. 转-Spring Framework中的AOP之around通知

    Spring Framework中的AOP之around通知 http://blog.csdn.net/xiaoliang_xie/article/details/7049183 标签: spring ...

随机推荐

  1. 解析关于Tomcat Servlet-request的获取请求参数及几种常用方法

    摘要:本文主要讲解Tomcat之Servlet-request请求参数.Servlet转发机制.常用方法 本文分享自华为云社区<浅谈Tomcat之Servlet-request获取请求参数及常用 ...

  2. corundum:100GNIC学习(三)——恢复工程

    前文:(一)https://www.cnblogs.com/shroud404/p/15364812.html (二)https://www.cnblogs.com/shroud404/p/15412 ...

  3. 《用Python写网络爬虫》pdf高清版免费下载

    <用Python写网络爬虫>pdf高清版免费下载地址: 提取码:clba 内容简介  · · · · · · 作为一种便捷地收集网上信息并从中抽取出可用信息的方式,网络爬虫技术变得越来越有 ...

  4. shell实现接口初次失败告警,恢复也发送一次通知

    1.该shell判断 第一次失败告警,接口恢复发送一次通知 参数:一个参数接口返回结果0 表示成功 1表示失败 脚本详情 [root@localhost bd]# more bd-new.sh #!/ ...

  5. Java异常之Error和Exception

    异常Exception 实际工作中,遇到的情况不可能是非常完美的.比如:你写的某个模块,用户输入不一定符合你的要求.你的程序要打开某个文件,这个文件可能不存在或者文件格式不对,你要读取数据库的数据,数 ...

  6. kubectl查询日志命令

    防水堡 bug日志定位命令: docker logs --tail 100 xxx:xxx 是容器的id 或者名称kubectl logs-f --tail 100 xxx:xxx 是pod 的id, ...

  7. C++数组(一):一维数组

    C++一维数组 C++数组的定义方式 数据类型 数组名[数组长度]; 例子:int arr[3]; arr[0] = 1; arr[1] = 2; arr[2] = 3; 数据类型 数组名[数组长度] ...

  8. 免费语音转文字----使用Adobe Premiere Pro

    软件版本:Adobe Premiere Pro 2023   打开Adobe Premiere Pro,新建项目:   将要转为文字的录音拖入轨道:   序列→自动转录序列:   选择想要的设置,转录 ...

  9. vim自动输入P的问题

    最近新租的centos8云服务器默认用的vim8.0,发现一个bug,就是每次打开文件,自动输入了一个P,原来是8.0的一个bug,升级版本可以解决 参考https://www.jianshu.com ...

  10. PLC数据块中的偏移量

    PLC数据块中的偏移量是什么? 偏移量定义为:把存储单元的实际地址与其所在段的段地址之间的距离称为段内偏移,也称为"有效地址或偏移量". 段地址左移四位,与有效地址相加,就构成了逻 ...