在没有 Spring MVC 的情况下使用 Spring 会话范围的 Bean

Using Spring Session-Scoped Beans without Spring MVC

我正在考虑使用带有 Spring 的会话作用域 bean,而不是创建会话属性并不断地转换和检查它们是否存在。问题是我没有使用 Spring MVC,所以我不确定如何指定当前会话是什么。我正在使用的应用程序有一个内部 MVC 结构,我们只有一个或两个应用程序访问点,所以做一些变通办法没什么大不了的。

我做了很多搜索,但每当我说 "not Spring MVC" 或不说 "Spring MVC" 时,我只会得到谈论 Spring MVC 的结果。

来自docs

If you use a Servlet 2.5 web container, with requests processed outside of Spring’s DispatcherServlet (for example, when using JSF or Struts), you need to register the org.springframework.web.context.request.RequestContextListener ServletRequestListener. For Servlet 3.0+, this can done programmatically via the WebApplicationInitializer interface. Alternatively, or for older containers, add the following declaration to your web application’s web.xml file:

<web-app>
  ...
  <listener>
    <listener-class>
        org.springframework.web.context.request.RequestContextListener
    </listener-class>
  </listener>
  ...
</web-app>