SpringBoot实现AOP

SpringBoot实现AOP

依赖

<dependency>
       <groupId>org.springframework.boot</groupId>
       <artifactId>spring-boot-starter-aop</artifactId>
</dependency>

配置

说明:Spring boot2.x 中AOP现在默认使用的CGLIB代理,假如需要使用JDK动态代理可以在配置文件(applicatiion.properties)中进行如下配置:

spring.aop.proxy-target-class=false

使用

使用推荐基于注解进行使用, 可参考spring中使用AOP Spring 使用AOP

如果你坚决使用配置文件, 哪么请定义一个配置类

@Configuration
@ImportResource("classpath:applicationContext.xml")
public class SpringConfig {

}

applicationContext.xml配置文件中配置xml即可

原文地址:https://www.cnblogs.com/zpKang/p/13374318.html