Spring3“session”范围和IllegalStateException甚至已经定义了proxy和RequestCntextListerner

时间:2011-12-02 08:23:22

标签: spring session struts2 annotations

我在Websphere 7中部署时遇到此错误。但它在Tomcat 7中运行正常。这是一种奇怪的行为。

  

无法实例化Action,...:当前线程的范围'session'无效;考虑为此bean定义范围代理....在这种情况下,使用RequestContextListenerRequestContextFilter公开当前请求。

我使用注释配置使用Spring 3 + Struts2 这是我的配置:

动作配置:

@Bean 
@Scope(value="session", proxyMode=ScopedProxyMode.TARGET_CLASS) 
public sws.web.utilization.reports.Action public_utilization_reports(){
    sws.web.utilization.reports.Action action = new sws.web.utilization.reports.Action();       
    return action;
}

Web.xml中

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4"
    xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>sws-web</display-name>

<!-- ============================================================================== -->
<!-- Spring Configuration parameters -->
<!-- ============================================================================== -->
<context-param>
    <param-name>contextClass</param-name>
    <param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value>
</context-param>

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
        sws.domain.config.SWSDomainConfig,      
        sws.web.config.ActionsConfig
    </param-value>
</context-param>


<!-- ============================================================================== -->
<!-- Filters -->
<!-- ============================================================================== -->
<filter>
    <filter-name>ResponseOverrideFilter</filter-name>
    <filter-class>org.displaytag.filter.ResponseOverrideFilter</filter-class>
</filter>

<filter>
    <filter-name>HibernateSessionConversationFilter</filter-name>
    <filter-class>pnd.core.web.filter.HibernateSessionConversationFilter</filter-class>
    <init-param>
        <param-name>sessionFactoryBeanName</param-name>
        <param-value>hibernateSessionFactory</param-value>
    </init-param>
</filter>

<filter>
    <filter-name>struts2</filter-name>
    <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>

<filter-mapping>
    <filter-name>HibernateSessionConversationFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
    <filter-name>ResponseOverrideFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

<!-- ============================================================================== -->
<!-- Listeners -->
<!-- ============================================================================== -->
<!-- Spring Listener -->

<listener>
    <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
 <!--Support the scoping of beans at the request, session, and global session levels (web-scoped beans) -->

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


<!-- Struts Tiles Listener -->

<listener>
    <listener-class>
        org.apache.struts2.tiles.StrutsTilesListener
    </listener-class>
</listener>

<welcome-file-list>     
    <welcome-file>index.jsp</welcome-file>
</welcome-file-list>

请帮忙。提前致谢

1 个答案:

答案 0 :(得分:0)

I still use jsp version 2.4
and use RequestcontextFiler rather than RequestContextListner. it worked fine.

<filter>
<filter-name>RequestContextFilter</filter-name>
<filter-class>org.springframework.web.filter.RequestContextFilter</filter-class>
</filter>