一、使用JDK工具keytool生成证书

keytool命令详解 https://blog.csdn.net/zlfing/article/details/77648430

keytool -genkey -alias tomcat -keypass password -storetype PKCS12 -keyalg RSA -keysize 2048 -validity 3650 -keystore keystore.p12 -storepass password -dname "CN=(AMS), OU=(National Innovation Institute of Additive Manufacturing), O=(National Innovation Institute of Additive Manufacturing), L=(Xian), ST=(Shanxi), C=(CN)"

二、将生成的文件copy到src下

三、配置yml文件

server:
#https 端口
port: 8443
ssl:
key-store: classpath:keystore.p12
key-store-password: password
keyStoreType: PKCS12
keyAlias: tomcat
#http端口
http:
port: 7000

四、重定向http到https

在配置类中加入

   /**
* http auto to https
*
* @return
*/
@Bean
public EmbeddedServletContainerFactory servletContainer()
{
TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory()
{
@Override
protected void postProcessContext(Context context)
{
SecurityConstraint securityConstraint = new SecurityConstraint();
securityConstraint.setUserConstraint("CONFIDENTIAL");
SecurityCollection collection = new SecurityCollection();
collection.addPattern("/*");
securityConstraint.addCollection(collection);
context.addConstraint(securityConstraint);
}
};
tomcat.addAdditionalTomcatConnectors(httpConnector());
return tomcat;
} public Connector httpConnector()
{
Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
connector.setScheme("http");
connector.setPort(7000);//http端口重定向到https端口
connector.setSecure(false);
connector.setRedirectPort(8443);
return connector;
}

springboot添加https的更多相关文章

  1. Springboot添加filter方法

    在springboot添加filter有两种方式: (1).通过创建FilterRegistrationBean的方式(建议使用此种方式,统一管理,且通过注解的方式若不是本地调试,如果在filter中 ...

  2. springboot添加邮件发送及压缩功能

    springboot添加邮件发送及文件压缩功能 转载请注明出处:https://www.cnblogs.com/funnyzpc/p/9190233.html 先来一段诗 ``` 就这样吧 忍受折磨 ...

  3. springboot添加多数据源连接池并配置Mybatis

    springboot添加多数据源连接池并配置Mybatis 转载请注明出处:https://www.cnblogs.com/funnyzpc/p/9190226.html May 12, 2018  ...

  4. SpringBoot学习(3)-SpringBoot添加支持CORS跨域访问

    SpringBoot学习(3)-SpringBoot添加支持CORS跨域访问 https://blog.csdn.net/yft_android/article/details/80307672

  5. SpringBoot添加对Mybatis分页插件PageHelper的支持

    1.修改maven配置文件pom.xml,添加对pageHelper的支持: <!--pagehelper--> <dependency> <groupId>com ...

  6. 腾讯云域名申请+ssl证书申请+springboot配置https

    阿里云域名申请 域名申请比较简单,使用微信注册阿里云账号并登陆,点击产品,选择域名注册 输入你想注册的域名 进入域名购买页面,搜索可用的后缀及价格,越热门的后缀(.com,.cn)越贵一般,并且很可能 ...

  7. cas+tomcat+shiro实现单点登录-1-tomcat添加https协议

    目录 1.tomcat添加https安全协议 2.下载cas server端部署到tomcat上 3.CAS服务器深入配置(连接MYSQL) 4.Apache Shiro 集成Cas作为cas cli ...

  8. 八大免费SSL证书-给你的网站免费添加Https安全加密

    评论»   https://www.freehao123.com/top-8-free-ssl-cert/ 文章目录 Let's Encrypt StartSSL SSL CloudFlare SSL ...

  9. 使用Spring Boot开发Web项目(二)之添加HTTPS支持

    上篇博客使用Spring Boot开发Web项目我们简单介绍了使用如何使用Spring Boot创建一个使用了Thymeleaf模板引擎的Web项目,当然这还远远不够.今天我们再来看看如何给我们的We ...

随机推荐

  1. Pycharm添加python2解释器

    Anaconda3+python3环境下如何创建python2环境(win+Linux下适用,同一个anaconda下py2/3共存) conda info -e 查看python2的路径 Pycha ...

  2. y7000笔记本 darknet-yolo安装与测试(Ubuntu16.04+Cuda9.0+Cudnn7.1)

    https://zhuanlan.zhihu.com/p/41096599 1.先查看是否安装有以下组件,若有先考虑彻底删除再安装(安装严格按照下面顺序进行) 查看nvidia 版本 nvidia-s ...

  3. mybatis oracle mysql 批量插入时的坑爹问题--需谨记

    mybatis oracle mysql 批量插入一.oracle的批量插入方式insert into db(id, zgbh, shbzh) select '1', '2', '3' from du ...

  4. 3 Java 冒泡排序法

    冒泡排序( Bubble Sort)是一种简单的排序算法.它重复访问要数列, 一次比较两个元素,如果他们的顺序错误就把交换过来.访问数列工作是 一次比较两个元素,如果他们的顺序错误就把交换过来.访问数 ...

  5. SRS之SrsServer::cycle()

    1. SrsServer 相关类定义 1.1 SrsServer 类定义 /** * SRS RTMP server, initialize and listen, * start connectio ...

  6. 尚学堂requireJs课程---1、作用域回顾

    尚学堂requireJs课程---1.作用域回顾 一.总结 一句话总结: 尚学堂的课程的资料他的官网上面是有的 1.js作用域? ~ js中是函数作用域:局部变量的话要写var关键词 ~ 闭包可以解决 ...

  7. 【闭包】JS闭包深入理解

    先看题目代码: 1 2 3 4 5 6 7 8 9 10 11 12 function fun(n,o) {  console.log(o)  return {   fun:function(m){ ...

  8. Button.OnClientClick

    Button.OnClientClick Gets or sets the client-side script that executes when a Button control's Click ...

  9. CentOS6 Zabbix-Agent2.0安装脚本

    #! /bin/bash ##################################### #-----------------------------------# #------zabb ...

  10. ubuntu关于ssh协议登录问题

    说明 初始化系统默认不安装ssh如果你想要通过crt等工具连接,你需要手动安装ssh 1.安装ssh工具 使用ubuntu安装的命令sudo apt-get install openssh-serve ...