springboot添加https
一、使用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的更多相关文章
- Springboot添加filter方法
在springboot添加filter有两种方式: (1).通过创建FilterRegistrationBean的方式(建议使用此种方式,统一管理,且通过注解的方式若不是本地调试,如果在filter中 ...
- springboot添加邮件发送及压缩功能
springboot添加邮件发送及文件压缩功能 转载请注明出处:https://www.cnblogs.com/funnyzpc/p/9190233.html 先来一段诗 ``` 就这样吧 忍受折磨 ...
- springboot添加多数据源连接池并配置Mybatis
springboot添加多数据源连接池并配置Mybatis 转载请注明出处:https://www.cnblogs.com/funnyzpc/p/9190226.html May 12, 2018 ...
- SpringBoot学习(3)-SpringBoot添加支持CORS跨域访问
SpringBoot学习(3)-SpringBoot添加支持CORS跨域访问 https://blog.csdn.net/yft_android/article/details/80307672
- SpringBoot添加对Mybatis分页插件PageHelper的支持
1.修改maven配置文件pom.xml,添加对pageHelper的支持: <!--pagehelper--> <dependency> <groupId>com ...
- 腾讯云域名申请+ssl证书申请+springboot配置https
阿里云域名申请 域名申请比较简单,使用微信注册阿里云账号并登陆,点击产品,选择域名注册 输入你想注册的域名 进入域名购买页面,搜索可用的后缀及价格,越热门的后缀(.com,.cn)越贵一般,并且很可能 ...
- cas+tomcat+shiro实现单点登录-1-tomcat添加https协议
目录 1.tomcat添加https安全协议 2.下载cas server端部署到tomcat上 3.CAS服务器深入配置(连接MYSQL) 4.Apache Shiro 集成Cas作为cas cli ...
- 八大免费SSL证书-给你的网站免费添加Https安全加密
评论» https://www.freehao123.com/top-8-free-ssl-cert/ 文章目录 Let's Encrypt StartSSL SSL CloudFlare SSL ...
- 使用Spring Boot开发Web项目(二)之添加HTTPS支持
上篇博客使用Spring Boot开发Web项目我们简单介绍了使用如何使用Spring Boot创建一个使用了Thymeleaf模板引擎的Web项目,当然这还远远不够.今天我们再来看看如何给我们的We ...
随机推荐
- better-scroll 介绍
碰到一个项目,应该遵守两大规则: 1. 不要让项目产生过多的第三方依赖 2. 增强组件的应用率 尽可能的将东西写在组件里面,尽可能的将数据写活,通过组件通信来进行数据转换,用到的依赖处理,我们可以通过 ...
- EBS 修改系统颜色
1)修改 配置文件: Java 色彩设计,选择相应的颜色 2)清理高速缓存 注:如果不清理缓存,则要等15分钟后才显示变成新设定的颜色
- 使用 Itext 生成PDF
一.生成PDF,所需jar包(itext-2.0.8.jar,iTextAsian.jar) 在springboot中只需要引入依赖即可,依赖代码如下: <dependency> < ...
- OGG-01877 Missing explicit accessrule for server collector
OGG-01877 Missing explicit accessrule for server collector Table of Contents 1. OGG-01877 1 OGG-0187 ...
- 搭建Java服务器,并且实现远程安全访问linux系统
1.通过ssh实现安全远程访问linux系统 ssh :secure shell 加密: 1. 对称加密 (加密密钥与解密密钥相同) des ...
- Transfer 穿梭框
基础用法 Transfer 的数据通过 data 属性传入.数据需要是一个对象数组,每个对象有以下属性:key 为数据的唯一性标识,label为显示文本,disabled 表示该项数据是否禁止转移.目 ...
- shell中变量计算
year=44 1.let,不需要$引用变量 let m=year+3 echo $m 2.(()) m=$((year+3)) 3.[ ],注意两边一定要有空格 m=$[ year+3 ] 4. ...
- stegsolve---图片隐写查看器
今天做CTF隐写术的题偶然发现一隐写图片查看的神器------stegsolve,分享给大家 stegsolve下载地址:http://www.caesum.com/handbook/Stegsolv ...
- XML字符串和 java对象项目转换
这是之前写,仅供参考(如果缺少jar包可以私信我,CSDN现在下载的东西太费了,动不动就要积分,开源精神所剩无几了,也没办法都需要吃饭,可以理解) import javax.xml.bind.JAXB ...
- ABAP Field+offset字符串截取
*删除字符串末尾的字符 DATA:str TYPE string VALUE 'abc,defg,', sub_str TYPE string, num TYPE i. WRITE:/ str. nu ...