1. AOP 执行顺序对比
1.1 Spring4
Spring4 对应 SpringBoot 的版本就是 1.X
1.1.1 正常情况
- @Around环绕之前
- @Before
- 方法调用…
- @Around环绕之后
- @After
- @AfterReturning
1.1.2 异常情况
- @Around环绕之前
- @Before
- 方法调用…
- @After
- @AfterThrowing
1.2 Spring5
Spring5 对应 SpringBoot 的版本就是 2.X
1.2.1 正常情况
- @Around环绕之前
- @Before
- 方法调用…
- @AfterReturning
- @After
- @Around环绕之后
1.2.2 异常情况
- @Around环绕之前
- @Before
- 方法调用…
- @AfterThrowing
- @After
本文详细对比了Spring4和Spring5中AOP(面向切面编程)的执行顺序。在Spring4中,正常情况下@Around在@Before之前执行,@After在@AfterReturning之后;而在异常情况下,@After在@AfterThrowing之前。到了Spring5,正常流程下@AfterReturning移到了@After之前,而异常处理时@AfterThrowing先于@After执行。对于依赖AOP顺序的开发者,理解这些变化至关重要。
2万+

被折叠的 条评论
为什么被折叠?



