AOP MethodInterceptor中断struts2操作/页面 [英] AOP MethodInterceptor breaks struts2 Action/page
问题描述
我在使用struts2和aop时遇到了一个奇怪的问题.我需要拦截某些struts2动作以检查一些自定义设置.这些动作已被拦截,但它破坏了所有页面参数/表单值等:
I am having a wierd issue with struts2 and aop. I need to intercept certain struts2 actions for checking some custom settings. The actions are getting intercepted but it breaks all page parameters/form values etc:
AOP配置为:
<aop:advisor id="associateModuleCheck" advice-ref="associateModuleAdvice" pointcut="execution(* uk.co.company.package.webapp.action.*.ModuleA*.*(..))" order="1"/>
和方法拦截器
public Object invoke(MethodInvocation invocation) throws Throwable {
Class<?> targetClass = invocation.getThis().getClass();
// DO stuff
return invocation.proceed();
}
基本上,我可以看到动作方法被截获,但是当它返回到页面时,它将破坏所有表单值.(有些动作甚至无法到达MethodInterceptor方法,但我从Spring日志中可以看到它基本上已被拦截):
Basically I can see that the action methods are intercepted, but when it's returned to the page, it breaks all form values. (Some actions won't even reach the MethodInterceptor method but I can see from the Spring log that it's basically intercepted) :
候选人是:"/namespacebbb/ModuleAction/method.action";模式是/**;match = true
Candidate is: '/namespacebbb/ModuleAction/method.action'; pattern is /**; matched=true
之所以不使用Struts2拦截器,是因为我可以使用Spring AOP一次性配置很多动作.
The reason why I am not using Struts2 interceptor is because I can configure a whole lot of actions in one go using Spring AOP.
如果我删除了拦截器,一切都会正常.有人做过这些东西吗?知道有什么问题吗?
If I remove the interceptor everything works fine. Anybody done this stuff before? Any idea what's wrong?
更新:
尽管我最终还是使用了struts2拦截器,但是这个问题仍然存在.我发现了这个春季论坛问题,该问题与我的问题非常相似:
Though I finally ended up using a struts2 interceptor, this issue is still open. I found this spring forum question, which is very similar to my issue:
http://forum.spring.io/forum/spring-projects/aop/38625-aop-struts-2-help
推荐答案
经过一番挖掘,我认为我发现了这个问题(如果您使用Spring来帮助AOP,即使您不是可能需要一个不同的ObjectFactory),总之,就是要确保Struts ObjectFactory的设置正确:
After a bunch of digging, I think I found the issue (if you're using Spring to help with AOP, even if you're not you're probably going to need a different ObjectFactory), long and short of it is that you need to make sure that the struts ObjectFactory is setup properly:
<constant name="struts.objectFactory" value="org.apache.struts2.spring.StrutsSpringObjectFactory" />
<constant name="struts.objectFactory.spring.autoWire.alwaysRespect" value="true"/>
或
<constant name="struts.objectFactory" value="spring" />
<constant name="struts.objectFactory.spring.autoWire.alwaysRespect" value="true"/>
来源: http://www.javawebdevelop.com/3294124/
这篇关于AOP MethodInterceptor中断struts2操作/页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!