Spring Boot 使用AOP
Spring Boot 使用AOP
在pom文件中添加AOP依赖
org.springframework.boot
spring-boot-starter-aop 添加切入点类
@Component
@Aspect
public class LogAop {@Before("execution(* com.aimilin.demo..*.*(..))")
public void before() {
System.out.println("start ---- log");
}
@After("execution(* com.aimilin.demo..*.*(..))")
public void after(JoinPoint joinPoint) {
System.out.println(
"after --------log, Class: " + joinPoint.getTarget().getClass() + "\n" +
"Method: " + joinPoint.getSignature().getName() + "\n" +
"Args :" + Arrays.asList(joinPoint.getArgs()));
}
}
Spring Boot Aop常用配置
配置文件位置: AopAutoConfiguration是否启用AOP,默认启用
spring.aop.auto=true
true 使用JDK代理(类需要有接口),false - cgLib代理
spring.aop.proxy-target-class=true
4.
还没有评论,来说两句吧...