AOP: 面向切面编程[底层就是动态代理]
指程序在运行期间动态的将某段代码切入到指定方法位置进行运行的编程方式
引用:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.0.6.RELEASE</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>5.0.6.RELEASE</version>
</dependency>
@EnableAspectJAutoProxy
在配置类上添加@EnableAspectJAutoProxy开始AOP功能
Spring Aop的所有方法
@Before | 在目标方法运行前调用 |
@After | 在目标方法运行结束之后运行,无论正常或异常结束 |
@AfterReturning | 在目标方法正常返回之后运行 |
@AfterThrowing | 在目标方法出现异常后运行 |