腾讯云
登录腾讯云–搜索SSL证书
点击购买证书
选择免费型–【当然也可以选择收费的】,点击申请
填写证书信息
点击确认申请
阿里云
首先购买证书,流程与前面类似;购买好后在证书列表点击“证书申请”,并填写信息
按照提示的流程一步步填写;
在提示验证时检测 域名解析的列表是否自动填写 解析记录,若没有则需要根据弹出来的提示,手动填写
填写完成后,点击提交,等待证书审核【阿里的一般在10分钟以内,至少我的时这样的】
SpringBoot项目配置SSL证书
下载 IIS 格式的证书 并解压
一、将证书文件放置在项目的resources 目录下
二、application.yml配置
######Tomcat
server:
tomcat:
uri-encoding: UTF-8
max-threads: 1000
min-spare-threads: 30
port: 443
ssl:
key-store: classpath:证书文件名(*.pfx)
key-store-password: 证书密码
key-store-type: PKCS12
servlet:
context-path: /
三、启动类的配置
@SpringBootApplication
@MapperScan(basePackages = {"********"})
public class AdminApplication extends SpringBootServletInitializer {
Class[] sources = {RedisConfig.class, AdminApplication.class};
public static void main(String[] args) {
ApplicationContext context = SpringApplication.run(AdminApplication.class, args);
//通过工具类获取spring容器中的bean对象
SpringUtil.setApplicationContext(context);
// SpringApplication.run(sources, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
application.sources(this.getClass());
application.sources(RedisConfig.class);
return super.configure(application);
// return application.sources(AdminApplication.class);
};
@Bean
public ServletWebServerFactory servletContainer() {
TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory();
tomcat.addAdditionalTomcatConnectors(createHTTPConnector());
return tomcat;
}
private Connector createHTTPConnector() {
Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
//同时启用http(80)、https(443)两个端口
connector.setScheme("http");
connector.setSecure(false);
connector.setPort(80);
connector.setRedirectPort(443);
return connector;
}
}