Spring3“会话”范围和 IllegalStateException 甚至已经定义了代理和 RequestCntextListerner

发布于 2024-12-19 07:16:36 字数 4109 浏览 0 评论 0原文

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

无法实例化 Action,...:范围“会话”对于当前线程不活动;考虑为此 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>

请帮忙。提前致谢

I've got this error when deploying in Websphere 7. but it's working fine in Tomcat 7. It's such a strange behavior.

Unable to instantiate Action, ...: Scope 'session' is not active for the current thread; consider defining a scoped proxy for this bean.... In this case, use RequestContextListener or RequestContextFilter to expose the current request.

I use Spring 3 + Struts2 using annotation configuration
Here is my configurations:

Action configuration:

@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>

Please help. Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情徒 2024-12-26 07:16:36
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>
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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文