我有带有struts2 MVC和spring DI的web RestClient,并在登录后使用struts2-spring-plugin将Authenticated RestClient bean注入会话范围内的struts2 Actions。如果我在 web.xml 中有 struts2-spring-plugin 需要的 ContextLoaderListener
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
没有会话范围(我的 IDE 标记会话为红色),只有原型和单例可用:
<bean id="restClient" class="com.test.services.RestClient" scope="session">
<constructor-arg ref="dataSource"/>
</bean>
如果我在 web.xml RequestContextListener 会话范围出现
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
但是这个异常出现了完整的堆栈跟踪
IllegalStateException:未找到线程绑定请求:您是指实际 Web 请求之外的请求属性,还是在原始接收线程之外处理请求?
我知道如果我切换到 spring MVC 则不存在这个问题,但是我可以在会话范围内使用 spring bean 与 struts2 框架,还是 struts2 有任何替代方案?