SpringBoot 2.x中为tomcat配置ssl(https)支持

编程入门 行业动态 更新时间:2024-10-24 04:34:08

SpringBoot 2.x<a href=https://www.elefans.com/category/jswz/34/1770694.html style=中为tomcat配置ssl(https)支持"/>

SpringBoot 2.x中为tomcat配置ssl(https)支持

参考来源:.html

配置证书:

keytool -genkeypair -alias tomcat -keyalg RSA -keystore tomcat.key

依次填入以下内容:

mcat.key
输入密钥库口令:
再次输入新口令:
您的名字与姓氏是什么?[Unknown]:  localhost
您的组织单位名称是什么?[Unknown]:  localhost
您的组织名称是什么?[Unknown]:  xxx Co,.Ltd
您所在的城市或区域名称是什么?[Unknown]:  KunShan
您所在的省/市/自治区名称是什么?[Unknown]:  SuZhou
该单位的双字母国家/地区代码是什么?[Unknown]:  China
CN=localhost, OU=localhost, O="xxxCo,.Ltd", L=KunShan, ST=SuZhou, C=Chin
a是否正确?[否]:y输入 <tomcat> 的密钥口令(如果和密钥库口令相同, 按回车):
再次输入新口令:

把生成的证书放入 resources目录

配置application.yml

debug: true
server:port: 8110tomcat:max-threads: 800accept-count: 30000min-spare-threads: 20max-connections: 30000ssl:key-store: classpath:tomcat.keykey-store-type: JKSkey-alias: tomcat#证书密码key-store-password: xxxx

中途遇到报错:

2019-09-09 08:43:49.752 default [main] DEBUG o.s.b.d.LoggingFailureAnalysisReporter - Application failed to start due to an exception
org.springframework.boot.web.embedded.tomcat.ConnectorStartFailedException: Connector configured to listen on port 8110 failed to startat org.springframework.boot.web.embedded.tomcat.TomcatWebServer.checkThatConnectorsHaveStarted(TomcatWebServer.java:228)at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.start(TomcatWebServer.java:203)at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.startWebServer(ServletWebServerApplicationContext.java:300)at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.finishRefresh(ServletWebServerApplicationContext.java:162)at org.springframework.context.support.AbstractApplicationContext.__refresh(AbstractApplicationContext.java:553)at org.springframework.context.support.AbstractApplicationContext.jrLockAndRefresh(AbstractApplicationContext.java:40002)at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:41008)at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140)at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759)at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:395)at org.springframework.boot.SpringApplication.run(SpringApplication.java:327)at org.springframework.boot.SpringApplication.run(SpringApplication.java:1255)at org.springframework.boot.SpringApplication.run(SpringApplication.java:1243)at commarch.web.WebApplication.main(WebApplication.java:34)
2019-09-09 08:43:49.752 default [main] ERROR o.s.b.d.LoggingFailureAnalysisReporter - 

解决方法:

参考来源:Spring Boot- The Tomcat connector configured to listen on port 8080 failed to start

SpringBoot 2.x

新增一个组件类

  
@Component
public class CustomContainer implements WebServerFactoryCustomizer<ConfigurableServletWebServerFactory> {@Value("${server.port}")int serverPort;@Overridepublic void customize(ConfigurableServletWebServerFactory factory) {factory.setPort(serverPort);}
}
 

 

 

 SpringBoot 1.x解决方法:

import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer;
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
import org.springframework.stereotype.Component;@Component
public class CustomContainer implements EmbeddedServletContainerCustomizer {@Overridepublic void customize(ConfigurableEmbeddedServletContainer container) {container.setPort(8085);}}

 

转载于:.html

更多推荐

SpringBoot 2.x中为tomcat配置ssl(https)支持

本文发布于:2024-02-27 04:56:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1705253.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:中为   SpringBoot   https   ssl   tomcat

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!