方法一 application.yml 里设置

server:
port: 80
servlet:
session:
tracking-modes: cookie
cookie:
http-only: true

方法二 启动类继承SpringBootServletInitializer 类,重写 onStartup 方法

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.SessionCookieConfig;
import javax.servlet.SessionTrackingMode;
import java.util.Collections; @SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
public class NdaDemoApplication extends SpringBootServletInitializer { public static void main(String[] args) {
SpringApplication.run(NdaDemoApplication.class, args);
}
public void onStartup(ServletContext servletContext)throws ServletException {
super.onStartup(servletContext);
servletContext.setSessionTrackingModes(Collections.singleton(SessionTrackingMode.COOKIE));
SessionCookieConfig sessionCookieConfig = servletContext.getSessionCookieConfig();
sessionCookieConfig.setHttpOnly(true);
}
}

最新文章

  1. JAVA集合
  2. Linux 磁盘自检介绍
  3. ElasticSearch 入门笔记1
  4. C#路径 (转载)
  5. SWFUpload下载地址
  6. Jersey Restful部署到Tomcat注意事项
  7. 非原生APP开发中可以用到的JQ插件
  8. HDU 1228 A + B 浙江大学研究生冠军
  9. 1.1XAF框架开发视频教程-简单的订单管理实现过程,视频,提纲,及教程源码
  10. java常见文件操作
  11. GoldenGate 复制进程报错"OGG-01296 Error mapping",丢弃文件报错“Mapping problem with delete record (target format)”,且实际条目存在
  12. JS中call,apply,bind方法的总结
  13. ●HDU 3689 Infinite monkey theorem
  14. 数据结构之Trie树
  15. [orleans2.1]这是你没玩过的船新版本
  16. LogHelper 日志
  17. SSH(poderosa)を使って、さくらのMySQLサーバーに接続する方法
  18. Python文本处理
  19. ElasticSearch 分组查询的几个例子
  20. $Django 客户端->wsgi->中间组件->urls->views(model,template) 总结+补充(事物,choices,inclusion_tag)!

热门文章

  1. ubuntu-网络配置文件
  2. edgex0.7.1_1.0.1的X86编译和交叉编译
  3. Andrew Ng机器学习 四:Neural Networks Learning
  4. APS实现的要点与难点
  5. CentOS7怎样安装Jenkins
  6. SourceTree&Git -01 -代码拉取推送流程 -提交时的相关注意事项
  7. 1216 Vue基础
  8. 《3+1团队》【Beta】Scrum meeting 3
  9. js与jquery中html() text() val()中的区别
  10. Spring源码窥探之:xxxAware接口