0

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

注入自动装配的依赖项失败;嵌套异常是 org.springframework.beans.factory.BeanCreationException:无法自动装配方法:.... 范围“会话”对于当前线程无效;如果您打算从单例中引用它,请考虑为该 bean 定义一个作用域代理;嵌套异常是 java.lang.IllegalStateException:未找到线程绑定请求:您是指实际 Web 请求之外的请求属性,还是在原始接收线程之外处理请求?如果您实际上是在 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?

4

1 回答 1

0

According to error you can not autowire session scope class because your singleton classes loaded when application starts. In the beginning session does not exist.

You need to create proxy interface

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

于 2014-10-23T21:54:14.987 回答