简体   繁体   English

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

[英]Using Spring Session-Scoped Beans without Spring MVC

I am thinking of using session scoped beans with Spring instead of making session attributes and constantly casting and checking if they exist yet. 我正在考虑将会话范围的Bean与Spring一起使用,而不是创建会话属性并不断地转换和检查它们是否存在。 The problem is that I am not using Spring MVC, so I am not sure how I can specify what the current session is. 问题是我没有使用Spring MVC,所以我不确定如何指定当前会话是什么。 The application I am working with has an in-house MVC structure, and we only have one or two access points to the application, so it would not be a big deal to do some sort of workaround. 我正在使用的应用程序具有内部MVC结构,并且我们只有一个或两个访问该应用程序的访问点,因此进行某种变通办法并不重要。

I have done many searches, but whenever I say "not Spring MVC" or without "Spring MVC" I only get results that talk about Spring MVC. 我进行了许多搜索,但是每当我说“不是Spring MVC”或不显示“ Spring MVC”时,我只会得到谈论Spring MVC的结果。

From the 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. 如果使用Servlet 2.5 Web容器,并且在Spring的DispatcherServlet外部处理请求(例如,使用JSF或Struts时),则需要注册org.springframework.web.context.request.RequestContextListener ServletRequestListener。 For Servlet 3.0+, this can done programmatically via the WebApplicationInitializer interface. 对于Servlet 3.0+,可以通过WebApplicationInitializer接口以编程方式完成此操作。 Alternatively, or for older containers, add the following declaration to your web application's web.xml file: 或者,或者对于较旧的容器,将以下声明添加到Web应用程序的web.xml文件中:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM