私は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 フレームワーク自体によって呼び出されるすべてのパブリック メソッドをインターセプトするにはどうすればよいですか? (Spring による TestComponent インスタンスの作成中の TestComponent.init() など) 現在、次のTestComponent.testMethod()
呼び出しによってのみインターセプトできます。
TestComponent testComponent = springContext.getBean(TestComponent.class);
testComponent.testMethod();