日期:2014-05-20 浏览次数:21178 次
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<bean id="before" class="com.aptech.aop.Before"></bean>
<bean id="after" class="com.aptech.aop.After"></bean>
<bean id="around" class="com.aptech.aop.Around"></bean>
<bean id="person" class="com.aptech.aop.Person"></bean>
<bean id="sbService" class="com.aptech.aop.Other"></bean>
<!-- 通过pointcut来指定哪些方法需要织入通知 -->
<!-- 以s开头的业务方法之前织入before通知 -->
<bean id="pointcut" class="org.springframework.aop.support.NameMatchMethodPointcutAdvisor">
<property name="mappedNames">
<list>
<value>s*</value>
</list>
</property>
<property name="advice">
<ref bean="before"/>
</property>
</bean>
<!-- 配置代理工厂 spring 1.2 -->
<bean id="proxy" class="org.springframework.aop.framework.ProxyFactoryBean">
<!-- 目标对象 -->
<property name="target">
<ref bean="person"/>
</property>
<!-- 目标对象实现的接口 -->
<property name="proxyInterfaces">
<list>
<value>com.aptech.aop.IPerson</value>
</list>
</property>
<!-- 指定advice或者pointcut -->
<property name="interceptorNames">
<list>
<value>pointcut</value>
</list>
</property>
</bean>
<!-- 自动代理 spring 2.0 -->
<bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<property name="beanNames">
<list>
<value>person</value> <!-- id值,不是类名 -->
<value>*Service</value>
</list>
</property>
<property name="interceptorNames">
<list>
<value>around</value>
</list>
</property>
</bean>
</beans>