Spring不同版本的AOP
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的更多相关文章
- spring之初识Ioc&Aop
Spring框架的作用 spring是一个轻量级的企业级框架,提供了ioc容器.Aop实现.dao/orm支持.web集成等功能,目标是使现有的java EE技术更易用,并促进良好的编程习惯. Spr ...
- 转:Spring历史版本变迁和如今的生态帝国
Spring历史版本变迁和如今的生态帝国 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/bntX2jSQfEHy7/article/deta ...
- Spring 使用xml配置aop
1.xml文件需要引入aop命名空间 2.xml内容: <?xml version="1.0" encoding="UTF-8"?> <bea ...
- Spring MVC 中使用AOP 进行统一日志管理--注解实现
1.AOP简介 AOP称为面向切面编程 AOP的基本概念 (1)Aspect(切面):通常是一个类,里面可以定义切入点和通知 (2)JointPoint(连接点):程序执行过程中明确的点,一般是方法的 ...
- [转]Spring历史版本变迁和如今的生态帝国
前两篇: 为什么要有Spring? 为什么要有Spring AOP? 前两篇从Web开发史的角度介绍了我们在开发的时候遇到的一个个坑,然后一步步衍生出Spring Ioc和Spring AOP的概念雏 ...
- -手写Spring注解版本&事务传播行为
视频参考C:\Users\Administrator\Desktop\蚂蚁3期\[www.zxit8.com] 0018-(每特教育&每特学院&蚂蚁课堂)-3期-源码分析-手写Spri ...
- spring boot: filter/interceptor/aop在获取request/method参数上的区别(spring boot 2.3.1)
一,filter/interceptor/aop在获取参数上有什么区别? 1,filter可以修改HttpServletRequest的参数(doFilter方法的功能), interceptor/a ...
- Spring的IOC和AOP之深剖
今天,既然讲到了Spring 的IOC和AOP,我们就必须要知道 Spring主要是两件事: 1.开发Bean:2.配置Bean.对于Spring框架来说,它要做的,就是根据配置文件来创建bean实例 ...
- Spring(6)—— AOP
AOP(Aspect-OrientedProgramming)面向切面编程,与OOP完全不同,使用AOP编程系统被分为切面或关注点,而不是OOP中的对象. AOP的引入 在OOP面向对象的使用中,无可 ...
- 转-Spring Framework中的AOP之around通知
Spring Framework中的AOP之around通知 http://blog.csdn.net/xiaoliang_xie/article/details/7049183 标签: spring ...
随机推荐
- python_添加中文编码和脚本
#!/usr/bin/env python 根据环境设置寻找python路径,必须放在第一行 # coding=utf-8 添加中文编码
- C端自动化实现:appium+winappdriver+python
一. 前言 有小伙伴有办公自动化的需求,特此出一篇C端自动化教程,并附带demo案例.C端的自动化比B端多一个appium,其他的操作大同小异. 二. 环境 appium:exe工具,用于启动服务,官 ...
- php pdo如何查询记录条数
转载php中文网:https://www.php.cn/php-ask-457710.html php pdo查询记录条数的方法:1.使用fetchAll函数查询,其语法如"$rows=$q ...
- 解决.Net Core3.0 修改cshtml代码之后必须重新生成才可以看到效果
1.安装Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation包 2.在Startup中ConfigureServices方法里面加入services.Ad ...
- 使用 UnoCSS shortcuts 简化 class
UnoCSS 确实简化了不少样式书写.也降低了 CSS 打包体积,提升了样式使用率.但样式太多的话,class 也写得多,比较费眼.所幸,UnoCSS 提供了 shortcuts 来简化 class, ...
- Vue学习笔记之组件与通信
1. 组件 1.1. 什么是组件 组件是可复用的Vue实例, 说白了就是一组可以重复使用的模板,通常一个应用会以一棵嵌套的组件树的形式来组织: 例如,你可能会有页头.侧边栏.内容区等组件,每个组件又包 ...
- fabric学习笔记11
fabric学习笔记10 20201303张奕博 2023.1.23 测试实践2 导入链码依赖包 package main import ( "github.com/hyperledger/ ...
- k8s ingress 报错整理
问题: Error from server (InternalError): error when creating "ingress-rules-demo1.yaml": Int ...
- ES6的总结的一些数组、字符串方法
1.数组的方法 unshift() 数组头部添加内容 push() 数组尾部添加内容 pop() 数组尾部删除内容 shift() 数组头部删除内容 sort() 数组排序 a-b 升序 b-a 降序 ...
- PHP后端 H5页面 打开微信小程序
/** * 功能:获取小程序access_token * Author:郑康凯 * Date: 2023/2/6 0006 15:14 */ public function hhsGetAccessT ...