如果公司有提供证书如:

拿到证书秘钥
可直接在springboot 的配置文件中配置:

server.ssl.key-store=classpath:cert.pfx
server.ssl.key-store-password=XXXXXXX
server.ssl.keyStoreType=PKCS12
server.ssl.key-password=XXXXXXXX

注意cert.pfx文件的位置

启动服务访问:这种只支持https
访问ok;

如果要同时支持http自动转换为https(springboot2.x)

import org.apache.catalina.Context;
import org.apache.catalina.connector.Connector;
import org.apache.tomcat.util.descriptor.web.SecurityCollection;
import org.apache.tomcat.util.descriptor.web.SecurityConstraint;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
/**
* Created by sWX605049 on 2019/7/31;
*/
@SpringBootApplication
public class AppApplication {
public static void main(String[] args) {
SpringApplication.run(AppApplication.class, args);
} *//**
* http重定向到https
* 由于低层获取动态token的业务不支持springboot2.x
* @return
*//*
@Bean
public TomcatServletWebServerFactory servletContainer() {
TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory() {
@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;
} //注意:https默认端口443 ,然后会跳转到访问80端口
@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;
}
}

springboot 1.5.x

/**
* @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(initiateHttpConnector());
return tomcat;
} /**
* @return Connector
*/
private Connector initiateHttpConnector() {
Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
connector.setScheme("http");
connector.setPort(8080); // http端口
connector.setSecure(false);
connector.setRedirectPort(8443); // application.properties中配置的https端口
return connector;
}

http://localhost:8080的时候系统会自动重定向到https://localhost:8443这个地址上

springboot https证书配置的更多相关文章

  1. HTTPS 证书配置

    HTTPS 证书配置 现在阿里云和腾讯云都支持申请 HTTPS 证书,这里不再提,有需要的可自行google解决方案. 本文主要介绍的是通过 letsencrypt 申请免费的HTTPS证书,并将其配 ...

  2. nginx 反向代理及 https 证书配置

    nginx 反向代理及 https 证书配置 author: yunqimg(ccxtcxx0) 1. 编译安装nginx 从官网下载 nginx源码, 并编译安装. ./configure --pr ...

  3. Https证书配置

    本文介绍配置免费证书的方法 具体步骤: 一.获取免费CA证书 步骤1到腾讯云找到: 二.申请完成 后域名验证指引 申请域名型证书,可以通过以下方式验证域名的所有权: 1. 手动 DNS 验证 通过解析 ...

  4. nginx 之 https 证书配置

    HTTPS原理和作用 为什么需要HTTPS 原因:HTTP不安全 传输数据被中间人盗用.信息泄露 数据内容劫持.篡改 HTTPS协议的实现 对传输内容进行加密以及身份验证 对称加密:加密秘钥和解密秘钥 ...

  5. springboot下https证书配置

    没有证书的小伙伴首先申请一个阿里云免费证书,按照我的步骤来操作 1.购买页面是这样的 按照顺序选择 神奇的一幕出现了 然后就去购买成功,我们会看到证书没有签发,我们需要去申请 填写需要绑定的域名 一般 ...

  6. apache2 以及https证书配置

    环境Ubuntu12.04 server 配置 1,首先在进入找到/etc/apache2/apache2.conf的配置文件,里面有包含了较多配置文件的路径如:httpd.conf/ports.co ...

  7. nginx https证书配置

    1. Nginx配置 server { listen 443; #指定ssl监听端口 server_name www.example.com; ssl on; #开启ssl支持 ssl_certifi ...

  8. Apache https 证书配置...

    没啥好说的..赋值粘贴 !! Listen 443 SSLSessionCache "shmcb:/apache/logs/ssl_scache(512000)" SSLSessi ...

  9. apache2 aliyun https证书配置

    SSLCertificateFile /etc/apache2/cert2019/2154762_www..com_public.crt SSLCertificateKeyFile /etc/apac ...

随机推荐

  1. JavaScript隐式类型转换(详解 +,-,*,/,==)

    JavaScript 在 运算 或 比较 之前, 会自动进行隐式类型转换. 下面我们来仔细讲一讲 + - * / == 运算符经历了哪些过程. 类型转换 ECMAScript 运行时系统会在需要时从事 ...

  2. Fiddler5 发送HTTP请求

    1.Fiddler Composer发送HTTP请求 Composer的编辑模式主要有2种:Parsed模式和Raw模式. 实例1:Composer发送get请求 实例2:Composer发送post ...

  3. JavaScript 模式》读书笔记(3)— 字面量和构造函数3

    这是字面量和构造函数的最后一篇内容,其中包括了JSON.正则表达式字面量,基本值类型包装器等知识点.也是十分重要的哦. 五.JSON JSON是指JavaScript对象表示以及数据传输格式.它是一种 ...

  4. mac开发错误:errSecInternalComponent

    errSecInternalComponent Command CodeSign failed with a nonzero exit code 修改方法: Build Settings -> ...

  5. VSCode 配置C++开发环境

    目录 安装VSCode应用程序 安装相关插件 汉化插件 C++编辑器插件 编写配置文件 tasks.json launch.json c_cpp_properties.json 第一步.安装VSCod ...

  6. 我的Keras使用总结(3)——利用bottleneck features进行微调预训练模型VGG16

    Keras的预训练模型地址:https://github.com/fchollet/deep-learning-models/releases 一个稍微讲究一点的办法是,利用在大规模数据集上预训练好的 ...

  7. Java基础语法(4)-流程控制

    title: Java基础语法(4)-流程控制 blog: CSDN data: Java学习路线及视频 1.程序流程控制 流程控制语句是用来控制程序中各语句执行顺序的语句,可以把语句组合成能完成一定 ...

  8. word加上尾注之后参考文献下面的横线去除

    Word 尾注上面的横线叫“××分隔符”,去掉的步骤是: 1. 先“视图”——“普通视图”: 2. 进入“引用”——“脚注”——“显示备注”: 3. 窗口下面出现了“尾注”,点击下拉菜单“所有尾注”那 ...

  9. Python数据处理(持续更新)

    #打开txt文件 #打开txt文件 with open('day02.txt') as f: for line in f.readlines(): aline=line.strip() bline=a ...

  10. 超参数、验证集和K-折交叉验证

    本文首发自公众号:RAIS ​前言 本系列文章为 <Deep Learning> 读书笔记,可以参看原书一起阅读,效果更佳. 超参数 参数:网络模型在训练过程中不断学习自动调节的变量,比如 ...