aop 对action执行拦截的方法,推荐给大家。
为了找aop拦截Action的方法,我找了很久,结果查到的大多是说aop不能拦截action中除了execute()方法的,为了能实现拦截于是就重写execute()方法。我觉得这样做还不如直接重写此方法,还做什么切面啊! 终于我找到了更好的解决方法如下: 1:action的配置,LogonAction继承于DispatchAction,(其他的Action类也行,但是不能在LogonAction类中继承或实现别的类或接口)
<bean name="/logon" class="com.juraglobal.softguard.action.LogonAction">
<property name="logonService">
<ref bean="logonService"/>
</property>
</bean>
2:advice的配置
<bean id="rightAdivce" class="com.juraglobal.softguard.common.web.action.RightAdivce"/>
3:autoproxy的配置:
<bean name="loggingAutoProxy"
class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<property name="beanNames">
<value>/logon</value>
</property>
<property name="interceptorNames">
<list>
<value>rightAdivce</value>
</list>
</property>
</bean>
4:RightAdivce类:
public class RightAdivce implements MethodBeforeAdvice {
private static final Logger log = Logger.getLogger(RightAdivce.class);
public void before(Method method, Object[] arg, Object target) throws Throwable {
}
}
请问要有没有具体的demo,可以麻烦发下我邮箱:185350541@qq.com 谢谢