Spring启动为嵌入式服务器配置自定义jsessionid [英] Spring boot configure custom jsessionid for embedded server

查看:1350
本文介绍了Spring启动为嵌入式服务器配置自定义jsessionid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想配置我的servlet上下文,例如查找自定义jsessionId键(请参阅更改cookie JSESSIONID名称

I want to configure my servlet context, such as sessing a custom jsessionId key (see Changing cookie JSESSIONID name)

我相信我可以在运行WAR文件时使用 SpringBootServletInitializer ,操纵 servletContext in onStartup()。但是,当我在嵌入式应用程序服务器上运行时,使用
new SpringApplicationBuilder()。run(),我不知道操作servlet的最佳位置上下文。

I believe I can use the SpringBootServletInitializer when running a WAR file, manipulating the servletContext in onStartup(). However, when I run on an embedded application server, using new SpringApplicationBuilder().run(), I don't know the best place to manipulate the servlet context.

推荐答案

Spring Boot 1.3 开始,您只需设置一个配置属性;

As of Spring Boot 1.3 you can simply set a configuration property;

Spring Boot 1.3,1.4,1.5

server.session.cookie.name = MYSESSIONID

Spring Boot 2.x

server.servlet.session.cookie.name = MYSESSIONID

比编写配置类简单得多。

A lot simpler than writing a configuration class.

参见 https://docs.spring.io/spring-boot/docs/current/reference /html/common-application-properties.html 了解更多与会话相关的属性。

See https://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html for more session related properties.

这篇关于Spring启动为嵌入式服务器配置自定义jsessionid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆