我是Spring AOP的新手。
使用基於註解的Spring配置:Spring AOP不攔截Spring容器內的方法
@Configuration
@EnableAspectJAutoProxy(proxyTargetClass=true)
@ComponentScan({"sk.lkrnac"})
看點:
@Aspect
@Component
public class TestAspect {
@Before("execution(* *(..))")
public void logJoinPoint(JoinPoint joinPoint){
....
}
}
春成分,它:
package sk.lkrnac.testaop;
@Component
public class TestComponent{
@PostConstruct
public void init(){
testMethod();
}
public void testMethod() {
return;
}
}
我怎麼能攔截由Spring框架本身召集所有公共的方法呢? (如TestComponent.init()創建由Spring的TestComponent實例的過程中) 目前我只能夠TestComponent.testMethod()
通過調用攔截:
TestComponent testComponent = springContext.getBean(TestComponent.class);
testComponent.testMethod();
-1,而不是問題所在。 – pap