Java setting tracking mode for session

If you avoid using xml for you configuration files like I do, but don’t want to pass the jsessionid around through the URL you can create a @Bean and use a lambda to set the tracking mode as follows

public class AuthProvidersSecurityConfig extends WebSecurityConfigurerAdapter {

    @Bean
    public ServletContextInitializer servletContextInitializer() {
      return servletContext -> {
        servletContext.setSessionTrackingModes(EnumSet.of(SessionTrackingMode.COOKIE));
      };
    }
}
Matt Busche's Picture

About Matt Busche

Software Engineer and Wheel of Fortune Expert If this article helped you, please consider buying me a book.

Des Moines, IA https://www.mrbusche.com