Spring/Struts从Tomcat到WPS/WAS移植的问题

问题:
javax.servlet.ServletException: Unable to instantiate Action, menuLoginAction, defined for 'menuLogin' in namespace '/sys'Error creating bean with name 'menuLoginAction': Scope 'session' is not active for the current thread; consider defining a scoped proxy for this bean if you intend to refer to it from a singleton; nested exception is java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request. - action - file:/C:/W7/profiles/AppSrv01/installedApps/localhostNode01Cell/CmccSzyd.ear/CmccSzydWeb.war/WEB-INF/classes/conf/struts/sys.xml:7:67

问题的本质:
在于struts和Spring对HTTP request的执行顺序要求,先是Spring(会写一些theadlocal的信息),然后才能是Struts.
用户的struts和Spring的定义:
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>


在WAS的webcontainer对于listener和filter执行的顺序有些奇怪。
如果是servlet,那么就是先执行listener然后是filter,那么就能满足Spring/Struts的要求。
如果不是servlet,那么会先执行filter。
用户的struts定义没有servlet,那么就根据struts的filter的url pattern, 去先执行了struts(没有Spring去处理HTTP request), 那么就拿不到相应的信息,出现的错误。

有两种解决方案:
1)Spring不使用listener,改成使用filter的方式,并把Spring的filter放在Struts前面。
<filter>
<filter-name>SpringRequestContextFiler</filter-name>
<filter-class>org.springframework.web.filter.RequestContextFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>SpringRequestContextFiler</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

2. 作个假的servlet,servlet什么也不处理,并设置servlet mapping为"/*",这样的话,就是先执行Spring的listener.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值