How to set cookie domain and path with Spring boot

zhe zhu picture zhe zhu · Jan 22, 2016 · Viewed 29.2k times · Source

In Tomcat, we can do it like this:

<Context useHttpOnly="true" sessionCookiePath="/"sessionCookieDomain=".XXXX.com"/>

I want to share the cookie for second level domain with Spring Boot, how to do it?

Answer

sthzg picture sthzg · Jan 22, 2016

Settings for the server that Spring Boot embeds are available as application properties (listed here under the section # EMBEDDED SERVER CONFIGURATION and the namespace server.servlet.session.cookie.*).

The equivalent to the Tomcat config from above should be:

# properties in /src/resources/application.properties
server.servlet.session.cookie.domain=.XXXX.com
server.servlet.session.cookie.http-only=true
server.servlet.session.cookie.path=/