Spring boot session timeout related configuration common for all server like tomcat, jetty, undertow. server.session.timeout  has been used to configure session timeout in spring boot application in  application.properties file.

server.session.timeout consider as seconds in the server configuration. This configuration is common for all server like tomcat, jetty, undertow.

1. Spring boot session timeout using application properties file

application.properties

server.session.timeout=1000         # session timeout in second 
server.session.cookie.max-age=1000 # Maximum age of the session cookie in seconds. also add if server.session.timeout not working

2. Spring boot session timeout programmatic

Configure spring boot session timeout using EmbeddedServletContainerCustomizer:

@SpringBootApplication
@ComponentScan // Using a root package also allows the @ComponentScan annotation to be used without needing to specify a basePackage attribute
public class SpringBootConfig {
     public static void main(String[] args) throws Exception {
          SpringApplication.run(SpringBootConfig.class, args); // it wil start application
    }    
    @Bean
    public EmbeddedServletContainerCustomizer containerCustomizer() {
        return (container -> {
            container.setSessionTimeout(1000);  // session timeout value
        });
    }
}

3. Spring boot session timeout while using JDBC store for session management

@EnableJdbcHttpSession(maxInactiveIntervalInSeconds = 1500)

 

 

Was this post helpful?

Leave a Reply

Your email address will not be published. Required fields are marked *