Enabling filtering for Tomcat by extending AbstractHttpSessionApplicationInitializer

In the previous step, Servlet Filter needs to be enabled on every request to the Servlet Container (Tomcat). The following snippet shows the code involved:

    public class Initializer     extends AbstractHttpSessionApplicationInitializer {      public Initializer() {        super(ApplicationConfiguration.class);       }    }

That's all the configuration you would need. The great thing with Spring Session is the fact that your application code talking to HTTPSession does not change! You can continue using the HttpSession interface, but in the background, Spring Session ensures that the session data is stored to an external data store - Redis in this example:

 req.getSession().setAttribute(name, ...

Get Mastering Spring 5.0 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.