【问题标题】:Spring not initializing session bean with requestcontextlistenerSpring 未使用 requestcontextlistener 初始化会话 bean
【发布时间】:2014-12-19 14:58:49
【问题描述】:

我正在尝试将我的 webapp 与 enunciate 分离,并且我有一个 web.xml,如下所示,但是当 Spring 3 引导时,我得到:

自动装配依赖注入失败;嵌套异常是 org.springframework.beans.factory.BeanCreationException:不能 autowire 方法:.... 范围“会话”对于当前不活动 线;如果您打算,请考虑为此 bean 定义一个作用域代理 从单例中引用它;嵌套异常是 java.lang.IllegalStateException:未找到线程绑定请求:是 您指的是实际 Web 请求之外的请求属性, 或在原始接收线程之外处理请求?如果 你实际上是在一个网络请求中操作并且仍然收到这个 消息,您的代码可能在 DispatcherServlet/DispatcherPortlet:在这种情况下,使用 RequestContextListener 或 RequestContextFilter 暴露当前 请求。

问题是我有一个请求上下文监听器:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC
  "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
  "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/applicationContext.xml</param-value>
    </context-param>
    <filter>
        <filter-name>org.springframework.security.filterChainProxy</filter-name>
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>org.springframework.security.filterChainProxy</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <listener>
        <listener-class>
            org.springframework.web.context.request.RequestContextListener
        </listener-class>
    </listener>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <servlet>
        <servlet-name>spring</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    </servlet>
    <servlet>
        <servlet-name>jersey2</servlet-name>
        <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
        <init-param>
            <param-name>com.sun.jersey.config.property.packages</param-name>
            <param-value>org.mypackage.web</param-value>
        </init-param>
        <init-param>
            <param-name>com.sun.jersey.config.feature.Trace</param-name>
            <param-value>true</param-value>
        </init-param>
        <init-param>
            <param-name>jaxrs.providers</param-name>
            <param-value>
                org.mypackage.web.rest.SerializableProvider
            </param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
      <servlet-mapping>
        <servlet-name>jersey2</servlet-name>
        <url-pattern>/rest/*</url-pattern>
      </servlet-mapping>
  <servlet-mapping>
    <servlet-name>jersey2</servlet-name>
    <url-pattern>/rest/myurl/session</url-pattern>
  </servlet-mapping>
</web-app>

那么为什么 Spring 不能正常启动呢?会不会是因为它的线程相关,并且sessionbean与sessionbean有关?

【问题讨论】:

    标签: spring spring-bean


    【解决方案1】:

    根据错误,您无法自动装配会话范围类,因为您的单例类是在应用程序启动时加载的。在开始的会话中不存在。

    你需要创建代理接口

    ex : @Scope(value = "session", proxyMode = ScopedProxyMode.INTERFACES)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-10-14
      • 1970-01-01
      • 1970-01-01
      • 2013-05-22
      • 1970-01-01
      • 2023-03-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多