AOP MethodInterceptor 中断 struts2 操作/页面 [英] AOP MethodInterceptor breaks struts2 Action/page

查看:31
本文介绍了AOP MethodInterceptor 中断 struts2 操作/页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用 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();
}

基本上可以看到action方法被拦截了,但是当它返回到页面时,它打破了所有表单值.(有些动作甚至不会到达 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';模式是/**;匹配=真

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 拦截器,但这个问题仍然存在.我发现this spring forum question,这与我的问题非常相似:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆