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 :

Spring boot config

Happy Learning 🙂

About the Author:

Avatar
Founder of onlinetutorialspoint.com Love Java, Python, Shell and opensource frameworks. Follow him on twitter and facebook for latest updates.

5 Comments

  1. Avatar
    Enoch May 22, 2018 at 1:57 pm - Reply

    Hi chandrashekhar,
    I ´ve just used the server.session.timeout in my application.properties file and it worked. Thanks

  2. Avatar
    krishna September 13, 2018 at 11:58 pm - Reply

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

  3. Avatar
    PJD November 7, 2018 at 1:19 am - Reply

    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.

  4. Avatar
    Bob March 5, 2019 at 3:47 am - Reply

    Not working for me too in Spring 3.x
    application.yml
    server:
    servlet:
    session:
    timeout: 60
    cookie:
    max-age: 60

  5. Avatar
    Majid Ali Khan November 19, 2020 at 7:22 pm - Reply

    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.

Leave A Comment