【发布时间】:2019-09-15 13:46:52
【问题描述】:
wanner 用最少的代码测试 spring boot(1.5.20) aop
类被优化,
@Component
public class Test {
public Test() {
System.out.println("test constr");
}
public void print() {
System.out.println("test print");
}
}
aop 类
@Aspect
@Component
public class LoggingAspect {
public LoggingAspect() {
System.out.println("aspect constr");
}
@After("execution(* *.Test.*(..))")
public void log(JoinPoint joinPoint) {
System.out.println("aspect print");
}
}
主类
@SpringBootApplication
@EnableAspectJAutoProxy(proxyTargetClass = true)
public class AopApplication implements CommandLineRunner {
public static void main(String[] args) {
SpringApplication.run(AopApplication.class, args);
}
@Autowired
private Test test;
@Override
public void run(String... strings) throws Exception {
test.print();
}
}
Test bean 和 LoggingAspect bean 都已创建。 Test.pring 被执行。但是,切入点 log() 永远不会被触发。我如此搜索并没有找到答案。我还尝试了使用 proxyTargetClass = True 或 False 的 @EnableAspectJAutoProxy。据我了解,此参数强制将 cglib 用于测试类。
请告诉我我错过了什么
【问题讨论】: