EN
Spring Boot 2.x - change session cookie max-age (JSESSIONID)
10 points
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):
xxxxxxxxxx
1
...
2
3
server.servlet.session.cookie.max-age=P365D
4
5
...
Where: P365D
means JSESSIONID
cookie will be stored 365 days in the web browser.
Screenshot:

Example values:
P7D
- 7 days,P30D
- 30 days,P730D
- around 2 years.
The below examples come from official Oracle docs (java.time.Duration
class).
xxxxxxxxxx
1
Examples:
2
3
"PT20.345S" -- parses as "20.345 seconds"
4
"PT15M" -- parses as "15 minutes" (where a minute is 60 seconds)
5
"PT10H" -- parses as "10 hours" (where an hour is 3600 seconds)
6
"P2D" -- parses as "2 days" (where a day is 24 hours or 86400 seconds)
7
"P2DT3H4M" -- parses as "2 days, 3 hours and 4 minutes"
8
"P-6H3M" -- parses as "-6 hours and +3 minutes"
9
"-P6H3M" -- parses as "-6 hours and -3 minutes"
10
"-P-6H+3M" -- parses as "+6 hours and -3 minutes"