日期:2014-05-16  浏览次数:20452 次

Spring MethodBeforeAdvice使用例子
MethodBeforeAdvice该拦截器会在调用dean的方法前执行
import java.lang.reflect.Method;

import org.springframework.aop.MethodBeforeAdvice;

public class DaoMethodBeforeAdvice implements MethodBeforeAdvice{

	public void before(Method arg0, Object[] arg1, Object arg2)
			throws Throwable {
		System.out.println("[DaoMethodBeforeAdvice]:" + arg0 + " : " + arg1[0]);
	}
}


配置文件信息
<bean id="beforeDaoAdvice" class="com.zakisoft.workspace.initcompt.advice.DaoMethodBeforeAdvice"></bean>
    <bean id="afterDaoAdvice" class="com.zakisoft.workspace.initcompt.advice.DaoMethodAfterAdvice"></bean>
    <bean id="throwsDaoAdvice" class="com.zakisoft.workspace.initcompt.advice.DaoThrowsAdvice"></bean>
    <bean id="aroundAdvice" class="com.zakisoft.workspace.initcompt.advice.DaoMethodAroundAdvice"></bean>
    
    <bean id="daoAopService" class="org.springframework.aop.framework.ProxyFactoryBean">
    	<property name="target" ref="mybatisDaoBean"></property>
    	<property name="interceptorNames">
    		<list>
    			<value>beforeDaoAdvice</value>
    			<value>afterDaoAdvice</value>
    			<value>throwsDaoAdvice</value>
    			<value>aroundAdvice</value>
    		</list>
    	</property>
    </bean>


完整代码请参考附件