<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> <!--<context:annotation-config/>自动扫描注解会出问题--> <bean id="beforeAdvice" class="advice.BeforeAdvice"></bean> <bean id="afterAdvice" class="advice.AfterAdvice"></bean> <bean id="aroundAdvice" class="advice.AroundAdvice"></bean> <bean id="throwsAdvice" class="advice.MyThrowsAdvice"></bean> <bean id="studenttarget" class="student.impl.StudentImpl"></bean> <!-- 使用Advisor拦截目标对象时,拦截目标对象中的login方法 --> <bean id="beforeAdvisor" class="org.springframework.aop.support.NameMatchMethodPointcutAdvisor"> <property name="advice"> <ref bean="beforeAdvice"/> </property> <property name="mappedNames"> <list> <value>login</value> </list> </property> </bean> <!-- 设定代理类 --> <bean id="student" class="org.springframework.aop.framework.ProxyFactoryBean"> <!-- 这里代理的是接口 --> <property name="proxyInterfaces"> <value>student.IStudent</value> </property> <!-- 程序中的Advice --> <property name="interceptorNames"> <list> <!--<value>beforeAdvice</value>--> <value>beforeAdvisor</value><!-- 注意这里,用于拦截某个目标对象中的指定方法 --> <value>afterAdvice</value> <value>aroundAdvice</value> <value>throwsAdvice</value> </list> </property> <!-- ProxyFactoryBean要代理的目标类 --> <property name="target"> <ref bean="studenttarget"/> </property> </bean> </beans>
转载于:https://blog.51cto.com/zuohao1990/1408978