最近在使用aop发现controller层可以进入aop切面,但是其他层切进入不了,像service和component
@Component
public class AopTest {
public String testAop(){
// int i = 5/0;
return "testAop";
}
}
后面发现加上个包扫描就可以aop了。
@ComponentScan
@Component
public class AopTest {
public String testAop(){
// int i = 5/0;
return "testAop";
}
}
总结可能原因:因为加@component或者@services层是容器初始化的时候注入了,但是使用aop时,切面扫描不到改包,所以价格包扫描。大概逻辑是这样。
欢迎指正!!