tkr*_*use 20 java jsessionid spring-boot
我想配置我的servlet上下文,例如设置自定义jsessionId键(请参阅更改cookie JSESSIONID名称)
我相信我可以使用SpringBootServletInitializer运行WAR文件时,操纵servletContext在onStartup().但是,当我在嵌入式应用程序服务器上运行时
new SpringApplicationBuilder().run(),我不知道操作servlet上下文的最佳位置.
Jam*_*ieB 44
从Spring Boot 1.3开始,您只需设置配置属性即可;
Spring Boot 1.3,1.4,1.5
server.session.cookie.name = MYSESSIONID
Run Code Online (Sandbox Code Playgroud)
Spring Boot 2.x
server.servlet.session.cookie.name = MYSESSIONID
Run Code Online (Sandbox Code Playgroud)
比编写配置类简单得多.
有关更多与会话相关的属性,请参阅https://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html.
And*_*son 25
ServletContextInitializer在应用程序的配置中声明一个bean:
@Bean
public ServletContextInitializer servletContextInitializer() {
return new ServletContextInitializer() {
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
servletContext.getSessionCookieConfig().setName("yourCookieName");
}
};
}
Run Code Online (Sandbox Code Playgroud)
或者,您的应用程序类本身可以实现ServletContextInitializer:
@Configuration
@EnableAutoConfiguration
@ComponentScan
public class Application implements ServletContextInitializer {
public static void main(String[] args) throws Exception {
SpringApplication.run(Application.class, args);
}
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
servletContext.getSessionCookieConfig().setName("yourCookieName");
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
24868 次 |
| 最近记录: |