public void setName(String name) {
this.name = name;
}
public void setAge(int age) {
this.age = age;
}
}
applicationContext-around.xml 文件
<!-- 配置目标bean实例 -->
<bean id="personTarget"
class=" yw.spring.demo.aop.around.PersonImpl">
<property name="name" value="Paulz" />
<property name="age" value="33" />
</bean>
<!-- 配置Around处理bean -->
<bean id="myAroundInterceptor"
class=" yw.spring.demo.aop.around.MyAroundInterceptor" />
<!-- 配置代理工厂 bean -->
<bean id="person"
class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="proxyInterfaces">
<value> yw.spring.demo.aop.around.IPerson</value>
</property>
<property name="target" ref="personTarget" />
<property name="interceptorNames">
<list>
<value>myAroundInterceptor</value>
</list>
</property>
</bean>
public static void main(String[] args) {
// 创建Spring容器实例
ApplicationContext context = new
ClassPathXmlApplicationContext(
"/applicationContext-around.xml");
// 获得AOP代理实例
IPerson person = (IPerson)
context.getBean("personOfAround");
// 执行AOP代理方法
person.info();
评论1
最新资源