In this tutorials, I am going to show how to set/change Tomcat session timeout in Spring boot application.
Spring Boot Tomcat session timeout :
We should be able to set the server.session.timeout in application.properties or application.yml file.
application.prroperties
server.session.timeout = 5000 // Session timeout in seconds
Most of the cases the above configuration will work, If not you should set the cookie max age along with session time out like below.
application.prroperties
server.session.cookie.max-age=5000
server.session.timeout=5000
Reference :
Happy Learning 🙂
Hi chandrashekhar,
I ´ve just used the server.session.timeout in my application.properties file and it worked. Thanks
Hi
in my spring boot application i have configured both server.session.cookie.max-age=60 and server.session.timeout=60.
but still the session is not getting expired. i am not sure whether i am missing other configuration..
Krishna, it depends on what version of Spring Boot you are using. The server.session.timeout no longer works in Spring 2.x, which requires server.servlet.session.timeout. Keep in mind this will only work in embedded Tomcat, not standalone. For that, you have to manually set the session timeout in the Tomcat server.xml. Having said all that, my session also doesn’t timeout even when setting it to 2 minutes and waiting 5 minutes. I’ve tried all the settings related to this and so far nothing works. That’s why I’m read this page.
Not working for me too in Spring 3.x
application.yml
server:
servlet:
session:
timeout: 60
cookie:
max-age: 60
This property was updated as of Spring Boot 2.0, now this is
server.servlet.session.timeout
this an example value 30m
If a duration suffix is not specified, seconds will be used.