Spring MethodBeforeAdvice使用例子

http://javapub.iteye.com/blog/903088

MethodBeforeAdvice该拦截器会在调用dean的方法前执行
Java代码 复制代码 收藏代码
  1. import java.lang.reflect.Method;
  2. import org.springframework.aop.MethodBeforeAdvice;
  3. public class DaoMethodBeforeAdvice implements MethodBeforeAdvice{
  4. public void before(Method arg0, Object[] arg1, Object arg2)
  5. throws Throwable {
  6. System.out.println("[DaoMethodBeforeAdvice]:" + arg0 + " : " + arg1[0]);
  7. }
  8. }


配置文件信息
Java代码 复制代码 收藏代码
  1. <bean id="beforeDaoAdvice" class="com.zakisoft.workspace.initcompt.advice.DaoMethodBeforeAdvice"></bean>
  2. <bean id="afterDaoAdvice" class="com.zakisoft.workspace.initcompt.advice.DaoMethodAfterAdvice"></bean>
  3. <bean id="throwsDaoAdvice" class="com.zakisoft.workspace.initcompt.advice.DaoThrowsAdvice"></bean>
  4. <bean id="aroundAdvice" class="com.zakisoft.workspace.initcompt.advice.DaoMethodAroundAdvice"></bean>
  5. <bean id="daoAopService" class="org.springframework.aop.framework.ProxyFactoryBean">
  6. <property name="target" ref="mybatisDaoBean"></property>
  7. <property name="interceptorNames">
  8. <list>
  9. <value>beforeDaoAdvice</value>
  10. <value>afterDaoAdvice</value>
  11. <value>throwsDaoAdvice</value>
  12. <value>aroundAdvice</value>
  13. </list>
  14. </property>
  15. </bean>


完整代码请参考附件
  • src.zip (73.5 KB)
  • 下载次数: 72

你可能感兴趣的:(spring)