Spring Boot中启动HTTPS
发布日期:2021-08-12 01:50:47 浏览次数:4 分类:技术文章

本文共 1765 字,大约阅读时间需要 5 分钟。

一,生成https 的证书

1,在相应的根目录下

keytool -genkey -alias tomcat  -storetype PKCS12 -keyalg RSA -keysize 2048  -keystore keystore.p12 -validity 3650

解释:

1.-storetype 指定密钥仓库类型 2.-keyalg 生证书的算法名称,RSA是一种非对称加密算法 3.-keysize 证书大小 4.-keystore 生成的证书文件的存储路径 5.-validity 证书的有效期(天)

  2,步骤

配置文件application.properties添加https支持: #设定端口号 service.port=8443#指定签名文件server.ssl.key-store=keystore.p12#指定签名密码server.ssl.key-store-password=111111(与生成的keystore.p12输入的密码 一直)#指定密钥仓库类型server.ssl.keyStoreType=PKCS12#设置别名server.ssl.keyAlias:tomcat

3,springboot 中创建configure ,使得http 自动转向https

@Bean    public EmbeddedServletContainerFactory servletContainer() {        TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory() {            @Override            protected void postProcessContext(Context context) {                SecurityConstraint constraint = new SecurityConstraint();                constraint.setUserConstraint("CONFIDENTIAL");                SecurityCollection collection = new SecurityCollection();                collection.addPattern("/*");                constraint.addCollection(collection);                context.addConstraint(constraint);            }        };        tomcat.addAdditionalTomcatConnectors(httpConnector());        return tomcat;    }    @Bean    public Connector httpConnector() {        Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");        connector.setScheme("http");        //Connector监听的http的端口号        connector.setPort(8080);        connector.setSecure(false);        //监听到http的端口号后转向到的https的端口号        connector.setRedirectPort(8443);        return connector;    }

4,测试 IP:port/xxxx ------------------>>>>>>>> https:IP:port/xxx

转载于:https://www.cnblogs.com/xiaohu1218/p/10724921.html

转载地址:https://blog.csdn.net/weixin_30642305/article/details/96007350 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:LVM
下一篇:android解决坚屏拍照和保存图片旋转90度的问题,并兼容4.0

发表评论

最新留言

不错!
[***.144.177.141]2024年03月02日 19时59分51秒

关于作者

    喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!

推荐文章

python信号采集代码_13行代码实现:Python实时视频采集(附源码) 2019-04-21
h5引入json_纯js直接引入json文件 2019-04-21
python格式化字符串总结_Python字符串处理方法总结 2019-04-21
python中true什么意思_python中的bool是什么意思 2019-04-21
jacobian 矩阵意义_Jacobian矩阵和Hessian矩阵的作用是什么? 2019-04-21
c++ jna 数据类型_JNA 使用总结 2019-04-21
python中如何遍历列表并将列表值赋予_python中如何实现遍历整个列表? 2019-04-21
apache php mysql架构图_Apache+PHP+MYSQL+Tomcat+JK架构设计技巧与应用实战 2019-04-21
xlnt库如何编译_最新mysql数据库源码编译安装。 2019-04-21
mysql 2003错误 10055_MYSQL无法连接---提示10055错误 2019-04-21
mysql redis缓存层_redis实现缓存的两种方式 2019-04-21
git 改local branch名字_用Git管理Latex写论文的工作流程 2019-04-21
mysql索引篇_MySQL索引篇 2019-04-21
有至少一个用MySQL_Mysql有用的面试题 2019-04-21
mysql select同时update_MySQLSELECT同时UPDATE同一张表 2019-04-21
mysql删除后数据库没变化_mysql之delete删除记录后数据库大小不变 2019-04-21
net mysql start3534_MySQL 5.7.14 net start mysql 服务无法启动-“NET HELPMSG 3534” 的奇怪问题... 2019-04-21
pta两个有序链表的合并_7-1 两个有序链表序列的合并 (20分) --- 内存问题再叙 2019-04-21
python问题描述怎么写_python写文件有时候写不进去怎么办 2019-04-21
qpython3安装lxml_在python的lxml中使用xml目录? 2019-04-21