我是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