Languages
[Edit]
EN

Spring Boot 2.x - change session cookie max-age (JSESSIONID)

10 points
Created by:
Violet-Hoffman
322

In this short article, we would like to show how to change JSESSIONID cookie max-age from Spring Boot 2.x application.properties file.

Quick solution (add a single line to your application.properties file):

...

server.servlet.session.cookie.max-age=P365D

...

Where: P365D means JSESSIONID cookie will be stored 365 days in the web browser.

Screenshot:

Spring Boot 2.x session expiration time set to 365 days (set in 2021-10-13) - displayed in Google Chrome DevTools
Spring Boot 2.x session expiration time set to 365 days (set in 2021-10-13) - displayed in Google Chrome DevTools

 

Example values:

  • P7D - 7 days,
  • P30D - 30 days,
  • P730D - around 2 years.

Oracle examples

The below examples come from official Oracle docs (java.time.Duration class).

Examples:

    "PT20.345S" -- parses as "20.345 seconds"
    "PT15M"     -- parses as "15 minutes" (where a minute is 60 seconds)
    "PT10H"     -- parses as "10 hours"   (where an hour is 3600 seconds)
    "P2D"       -- parses as "2 days"     (where a day is 24 hours or 86400 seconds)
    "P2DT3H4M"  -- parses as "2 days, 3 hours and 4 minutes"
    "P-6H3M"    -- parses as "-6 hours and +3 minutes"
    "-P6H3M"    -- parses as "-6 hours and -3 minutes"
    "-P-6H+3M"  -- parses as "+6 hours and -3 minutes"

References

  1. Duration - Oracle Docs
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join