Sprngboot HTTPS配置错误导致端口占用错误

在配置Springboot应用启用HTTPS时,出现端口占用错误。错误信息误导了排查方向,实际上问题出在`application.properties`中`key-store`的位置配置。正确配置应为`server.ssl.key-store: classpath:/key.p12`,而错误地写成了相对路径,导致应用无法找到key store文件,从而引发错误。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Springboot配置HTTPS非常简单,详见https://drissamri.be/blog/java/enable-https-in-spring-boot/
但在配置过程中遇到的诡异问题让我排查方向出现了错误。
按照文档配置好之后,启动springboot应用时,提示如下:

2019-07-19 13:46:57,914 [DEBUG] (main) ngFailureAnalysisReporter:37    Application failed to start due to an exception
org.springframework.boot.web.embedded.tomcat.ConnectorStartFailedException: Connector configured to listen on port 8251 failed to start
	at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.checkConnectorHasStarted(TomcatWebServer.java:228) ~[spring-boot-2.1.6.RELEASE.jar!/:2.1.6.RELEASE]
	at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.checkThatConnectorsHaveStarted(TomcatWebServer.java:220) ~[spring-boot-2.1.6.RELEASE.jar!/:2.1.6.RELEASE]
	at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.start(TomcatWebServer.java:200) ~[spring-boot-2.1.6.RELEASE.jar!/:2.1.6.RELEASE]
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.startWebServer(ServletWebServerApplicationContext.java:296) ~[spring-boot-2.1.6.RELEASE.jar!/:2.1.6.RELEASE]
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.finishRefresh(ServletWebServerApplicationContext.java:162) ~[spring-boot-2.1.6.RELEASE.jar!/:2.1.6.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:552) ~[spring-context-5.1.8.RELEASE.jar!/:5.1.8.RELEASE]
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.1.6.RELEASE.jar!/:2.1.6.RELEASE]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:742) [spring-boot-2.1.6.RELEASE.jar!/:2.1.6.RELEASE]
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:389) [spring-boot-2.1.6.RELEASE.jar!/:2.1.6.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:311) [spring-boot-2.1.6.RELEASE.jar!/:2.1.6.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1213) [spring-boot-2.1.6.RELEASE.jar!/:2.1.6.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1202) [spring-boot-2.1.6.RELEASE.jar!/:2.1.6.RELEASE]
	at oracle.KycApplication.main(KycApplication.java:21) [classes!/:?]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_211]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_211]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_211]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_211]
	at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:47) [kyc-ms-19.7-SNAPSHOT.jar:?]
	at org.springframework.boot.loader.Launcher.launch(Launcher.java:86) [kyc-ms-19.7-SNAPSHOT.jar:?]
	at org.springframework.boot.loader.Launcher.launch(Launcher.java:50) [kyc-ms-19.7-SNAPSHOT.jar:?]
	at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51) [kyc-ms-19.7-SNAPSHOT.jar:?]
2019-07-19 13:46:57,918 [ERROR] (main) ngFailureAnalysisReporter:40    

***************************
APPLICATION FAILED TO START
***************************

Description:

The Tomcat connector configured to listen on port 8251 failed to start. The port may already be in use or the connector may be misconfigured.

Action:

Verify the connector's configuration, identify and stop any process that's listening on port 8251, or configure this application to listen on another port.

上述错误信息描述十分具有迷惑性,笔者找遍了机器,也没找到8251端口被占用,当然这也是经验主义作祟,其实消息内也提示了可能配置信息有误,但笔者没有注意到。
最后在排查application.properties配置文件的时候才发现是key-store文件的位置写错了,我写的是:
server.ssl.key-store: key.p12
而文档中给出的是:
server.ssl.key-store:classpath:/key.p12
没有加入classpath,应用默认就回去当前启动位置所在的文件夹去找key store,当然找不到了,所以就报出来上述错误。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值