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

最新文章

  1. sql with as union all
  2. segues的类型
  3. java9-9 匿名内部类
  4. Vim的文件加密
  5. POJ 1316
  6. PHP移动互联网的发展票据(6)——MySQL召回数据库基础架构[1]
  7. Docker基本架构
  8. 使用swagger管理接口
  9. webpack打包优化
  10. Uart串口
  11. 人生苦短之HTTP协议及Requests库的方法
  12. MyBatis是如何解决Sql注入的
  13. C 语言中的 switch 语句 case 后面是否需要加大括号
  14. C:\\MFC控件大小随窗体大小而改变
  15. vue项目引入FastClick组件解决IOS系统下h5页面中的按钮点击延迟,连续点击无反应的问题
  16. Axure8.1.0.3372 注册码
  17. JS面向对象(封装,继承)
  18. Intent 对象在 Android 开发中的应用
  19. [小技巧]Linux的一些信息获取
  20. mysql 约束条件 外键 forigen key 介绍

热门文章

  1. P18_Day2.学习目标
  2. Session和Shiro的Session区别
  3. 微信小程序 添加域名
  4. vue中央事件
  5. 有趣的python库-pyttsx3
  6. 9.【go-kit教程】go-kit集成Prometheus
  7. PostgreSQL处理膨胀与事务回卷
  8. Android 之Map容器替换 SparseArray,ArrayMap,ArraySet
  9. spring boot 配置Bean
  10. 银河麒麟V10在线安装Postgresql步骤