AOP MethodInterceptor breaks struts2 Action/page

谁都会走 提交于 2019-12-25 17:01:45

问题


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:

The AOP configuration is:

<aop:advisor id="associateModuleCheck"  advice-ref="associateModuleAdvice"  pointcut="execution(* uk.co.company.package.webapp.action.*.ModuleA*.*(..))" order="1"/>

And the method Interceptor

public Object invoke(MethodInvocation invocation) throws Throwable {
        Class<?> targetClass = invocation.getThis().getClass();
        // DO stuff 
        return invocation.proceed();
}

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) :

Candidate is: '/namespacebbb/ModuleAction/method.action'; pattern is /**; matched=true

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?

Update:

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


回答1:


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"/>

or

<constant name="struts.objectFactory" value="spring" />
<constant name="struts.objectFactory.spring.autoWire.alwaysRespect" value="true"/>

source: http://www.javawebdevelop.com/3294124/



来源:https://stackoverflow.com/questions/20861063/aop-methodinterceptor-breaks-struts2-action-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!