gpt4 book ai didi

java - 在没有 Spring MVC 的情况下使用 Spring session 范围 Bean

转载 作者:太空宇宙 更新时间:2023-11-04 06:14:45 24 4
gpt4 key购买 nike

我正在考虑在 Spring 中使用 session 作用域 bean,而不是创建 session 属性并不断转换和检查它们是否存在。问题是我没有使用 Spring MVC,所以我不确定如何指定当前 session 是什么。我正在使用的应用程序具有内部 MVC 结构,并且我们只有一两个应用程序的访问点,因此采取某种解决方法并不是什么大问题。

我做了很多搜索,但每当我说“不是 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>

关于java - 在没有 Spring MVC 的情况下使用 Spring session 范围 Bean,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28239864/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com