ApplicationContext app = new ClassPathXmlApplicationContext("bean.xml");↓
ApplicationContext app =
new AnnotationConfigApplicationContext(SampleAopConfig.class);
bean.setTarget(sampleAopBean);この「setTarget」と「setInterceptorNames」が、先にbean.xmlで記述してあった<property name="target">と<property name="interceptorNames">に相当する処理、というわけです。
bean.setInterceptorNames("sampleMethodAdvice");
※リストが表示されない場合
AddBlockなどの広告ブロックツールがONになっているとリストなどが表示されない場合があります。これらのツールをOFFにしてみてください。
package com.tuyano.libro.aop; import org.springframework.aop.framework.ProxyFactoryBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @Configuration public class SampleAopConfig { private SampleAopBean sampleAopBean = new SampleAopBean("this is message bean."); private SampleMethodAdvice sampleMethodAdvice = new SampleMethodAdvice(); @Bean SampleAopBean sampleAopBean() { return sampleAopBean; } @Bean SampleMethodAdvice sampleMethodAdvice() { return sampleMethodAdvice; } @Bean ProxyFactoryBean proxyFactoryBean() { ProxyFactoryBean bean = new ProxyFactoryBean(); bean.setTarget(sampleAopBean); bean.setInterceptorNames("sampleMethodAdvice"); return bean; } }
<< 前へ |