一、使用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. oracle取出所有表和视图

    select c.TABLE_NAME, d.COMMENTS, d.table_type, (select wmsys.wm_concat(a.column_name) from user_cons ...

  2. scrapy pipeline

    pipeline的四个方法 @classmethod def from_crawler(cls, crawler): """ 初始化的时候,用以创建pipeline对象 ...

  3. phpstorm 比较修改过的代码 version control

  4. MySQL5.7快速修改表中字段长度

    在mysql 5.5版本时,商用环境升级,有一个表存在六千多万数据,升级时需要修改这个表其中一个varchar类型字段的长度,当时用了大概4个多小时,还没有结束,之后我们系统mysql升级到5.7版本 ...

  5. drawable SVG 使用

    Android会使用一些规则来去帮我们匹配最适合的图片.什么叫最适合的图片?比如我的手机屏幕密度是xxhdpi,那么drawable-xxhdpi文件夹下的图片就是最适合的图片.因此,当我引用andr ...

  6. LeetCode 分类颜色

    LeetCode   分类颜色 给定一个包含红色.白色和蓝色,一共 n 个元素的数组,原地对它们进行排序,使得相同颜色的元素相邻,并按照红色.白色.蓝色顺序排列. 此题中,我们使用整数 0. 1 和 ...

  7. JSTL核心标签库详解

    <c:out>标签 标签用于输出一段文本到浏览器中. 属性名 是否支持EL 属性类型 属 性 描 述 value true Object 指定要输出的内容 escapeXml true B ...

  8. javascript中ClassName属性的详解与实例

    在javascritp中,我们可以通过style属性可以控制元素的样式,从而实现行为层通过DOM的style属性去干预显示层显示的目标,但是这种方法是不好的,而且为了实现通过DOM脚本设置的样式,你不 ...

  9. c++传递函数当作对象传递

    c++中函数当作对象来传递,类似c#中的指针操作如: #include <iostream> using namespace std; int tst(int a){ cout<&l ...

  10. Introduction to pointers in C

    The basic purpose of developing a C programming tutorial for this website – CircuitsToday – is to ma ...