Joseph K. Strauss
Joseph K. Strauss

Reputation: 4903

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. The problem is that I am not using Spring MVC, so I am not sure how I can specify what the current session is. 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.

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.

Upvotes: 1

Views: 471

Answers (1)

a better oliver
a better oliver

Reputation: 26828

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. 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>

Upvotes: 1

Related Questions