Spring Boot: remove jsessionid from url
参考代码 :Spring Boot: remove jsessionid from url
我的SpringBoot用2.0.*,答案中的第一二个方案亲测无效。
应该在继承了Configuration里面加入第三种方案所示的代码
@Configuration
//WebMvcConfigurerAdapter在2.0.*中已作废,有WebMvcConfigurer,WebMvcConfigurationSupport两种方案。
//public class WebSecurityConfig extends WebMvcConfigurerAdapter{
public class WebSecurityConfig implements WebMvcConfigurer {
//public class WebSecurityConfig extends WebMvcConfigurationSupport {
@Bean
public ServletContextInitializer servletContextInitializer() {
return new ServletContextInitializer() { @Override
public void onStartup(ServletContext servletContext) throws ServletException {
servletContext.setSessionTrackingModes(Collections.singleton(SessionTrackingMode.COOKIE));
SessionCookieConfig sessionCookieConfig=servletContext.getSessionCookieConfig();
sessionCookieConfig.setHttpOnly(true);
}
}; } }
或者
@Configuration
//WebMvcConfigurerAdapter在2.0.*中已作废,有WebMvcConfigurer,WebMvcConfigurationSupport两种方案。
//public class WebSecurityConfig extends WebMvcConfigurerAdapter{
public class WebSecurityConfig implements WebMvcConfigurer {
//public class WebSecurityConfig extends WebMvcConfigurationSupport { @Bean
public ServletContextInitializer servletContextInitializer() {
return servletContext -> {
servletContext.setSessionTrackingModes(Collections.singleton(SessionTrackingMode.COOKIE));
SessionCookieConfig sessionCookieConfig=servletContext.getSessionCookieConfig();
sessionCookieConfig.setHttpOnly(true);
}; }
}
可以看到该段代码实现了以下接口
package org.springframework.boot.web.servlet; import javax.servlet.ServletContext;
import javax.servlet.ServletException; @FunctionalInterface
public interface ServletContextInitializer {
void onStartup(ServletContext servletContext) throws ServletException;
}
Spring Boot: remove jsessionid from url的更多相关文章
- Spring Boot实战之定制URL匹配规则
本文首发于个人网站:Spring Boot实战之定制URL匹配规则 构建web应用程序时,并不是所有的URL请求都遵循默认的规则.有时,我们希望RESTful URL匹配的时候包含定界符". ...
- Spring Boot 嵌入式 Tomcat 文件上传、url 映射虚拟路径
1.Java web 应用开发完成后如果是导入外置的 Tomcat 的 webapps 目录的话,那么上传的文件可以直接的放在应用的 web 目录下去就好了,浏览器可以很方便的进行访问. 2.Spri ...
- Spring Boot(一):快速开始
Spring Boot(一):快速开始 本系列文章旨在使用最小依赖.最简单配置,帮助初学者快速掌握Spring Boot各组件使用,达到快速入门的目的.全部文章所使用示例代码均同步Github仓库和G ...
- Spring Boot Admin Reference Guide
1. What is Spring Boot Admin? Spring Boot Admin is a simple application to manage and monitor your S ...
- Spring Boot admin 2.0 详解
一.什么是Spring Boot Admin ? Spring Boot Admin是一个开源社区项目,用于管理和监控SpringBoot应用程序. 应用程序作为Spring Boot Admin C ...
- Spring Boot探究之旅--启动分析
刚接触SpringBoot,感觉挺方便的,不用配置那么多乱七八糟的配置,很方便!酒饱思淫欲,得陇望蜀一下,看看SpringBoot到底怎么做到这么方便的. 首先呢,先来看个SpringBoot的hel ...
- spring boot架构浅谈
首先来说一下什么是spring boot架构 Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程.该框架使用了特定的方式来进行配置 ...
- Spring Boot实战之定制type Formatters
本文首发于个人网站:Spring Boot实战之定制type Formatters 前面我们有篇文章介绍了PropertyEditors,是用来将文本类型转换成指定的Java类型,不过,考虑到Prop ...
- spring boot 1.5.10.RELEASE ,spring boot admin 1.5.7 添加 security
生产环境的客户端actuator最好是加上security校验,不然配置信息不登录就能直接获取到 server端配置,参考官方 文档,https://codecentric.github.io/spr ...
随机推荐
- dataTable表头未对其解决方法
本文为博主原创,未经允许不得转载: 在tab页中使用dataTable时,默认显示的dataTable表头与数据显示正常,另一个的datatable则表头与数据未对其. 检查元素发现,datatabl ...
- 原生js 当前时间 倒计时代码
源:https://www.oschina.net/code/snippet_2318153_54763 <!DOCTYPE html> <html> <head> ...
- 在C#中理解和实现策略模式的绝对入门教程
介绍 本文的目的是理解战略模式的基础知识,并试图了解何时可以使用,并有一个基本的实现,以便更好地理解.在现实世界的应用中,这是无法实施战略模式的,所采用的例子也远没有实际可行.这篇文章的想法只是为了说 ...
- 定义统一的返回格式(controller)
一:单独创建一个类来表示返回结果 package com.jk51.commons.dto; /** * Created by Administrator on 2017/6/13. */ publi ...
- CentOS6.5下搭建LAMP+FreeRadius+Daloradius Web管理和TP-LINK路由器、H3C交换机连接,实现,上网认证和记账功能
什么是RADIUS服务: RADIUS:(Remote Authentication Dial In User Service)中文名为远程用户拨号认证服务,简称RADIUS,是目前应用最广泛的AAA ...
- ORA-03113: end-of-file on communication channel(归档满处理方法)
归档放在flash_recovery目录,由于归档占满了闪回目录,数据库启动报错ORA-03113: end-of-file on communication channel tail -1200f ...
- json文件不能有注释
之前一直忽视了这个问题,直接导致taiga-front的部署的时候不能通过其他IP访问. 如图: 首先是提示 app-loader.js:1 Your conf.json file is not a ...
- 对Maven项目进行强制更新
选中项目 然后 选中Force Update of Snapshots/Releases,点击OK即可. 此时pom.xml就不会报错了.
- unittest单元测试简单介绍
unittest单元测试框架不仅可以适用于单元测试,还可以适用WEB自动化测试用例的开发与执行,该测试框架可组织执行测试用例,并且提供了丰富的断言方法,判断测试用例是否通过,最终生成测试结果.今天笔者 ...
- Oracle:如何创建一个只有查看权限的用户
因为工作中测试环境和开发环境是分开的,所以开发有时处理bug时需要连接测试数据库,这样出现一个问题是有些开发会为了验证某些问题任意改动数据库的表和字段,对测试库造成污染.为了能够让开发连接测试环境,同 ...