The jsessionid
行为,与 STATELESS 无关。
最初,servlet 容器不知道客户端(浏览器)是否支持 cookie。
因此,在第一次请求页面时(通常是 HTTP GET):
- Servlet 容器将附加
;jsessionid=...
到所有 URL。
- servlet 容器将(尝试)设置一个 cookie
jsessionid
.
当点击链接或提交公式(HTTP GET/POST)时,浏览器会将 cookie 发送回服务器,当且仅当浏览器确实首先接受了 cookie 设置。
现在,servlet 容器可以识别,是否jsessionid
来自 cookie(通过 HTTP 请求标头传输)或 URL。
If the jsessionid
源自 cookie,servlet 容器将停止追加;jsessionid=...
到 URL。
如果jsessionid
源自您单击的 URL,它将继续附加;jsessionid=
到所有 URL。
这与 STATELESS 或任何其他配置无关SessionCreationPolicy
.
查看 Spring Security 文档SessionCreationPolicy
:
/** Always create an {@link HttpSession} */
ALWAYS,
/**
* Spring Security will never create an {@link HttpSession}, but will use the
* {@link HttpSession} if it already exists
*/
NEVER,
/** Spring Security will only create an {@link HttpSession} if required */
IF_REQUIRED,
/**
* Spring Security will never create an {@link HttpSession} and it will never use it
* to obtain the {@link SecurityContext}
*/
STATELESS
Update:
要通过 URL 禁用跟踪模式,请设置以下属性:
server.servlet.session.tracking-modes: COOKIE
See: https://docs.spring.io/spring-boot/docs/current/reference/html/appendix-application-properties.html