gpt4 book ai didi

java - 无法使用 SSL 运行 Spring Boot 应用程序

转载 作者:行者123 更新时间:2023-11-28 22:46:32 25 4
gpt4 key购买 nike

我无法使用 https 运行 spring boot 应用程序。我知道 Spring boot 使用嵌入式 tomcat 服务器

下面是堆栈跟踪

org.apache.catalina.LifecycleException: Protocol handler start failed
at org.apache.catalina.connector.Connector.startInternal(Connector.java:1008) ~[tomcat-embed-core-9.0.26.jar!/:9.0.26]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[tomcat-embed-core-9.0.26.jar!/:9.0.26]
at org.apache.catalina.core.StandardService.addConnector(StandardService.java:227) [tomcat-embed-core-9.0.26.jar!/:9.0.26]
at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.addPreviouslyRemovedConnectors(TomcatWebServer.java:263) [spring-boot-2.1.9.RELEASE.jar!/:2.1.9.RELEASE]
at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.start(TomcatWebServer.java:195) [spring-boot-2.1.9.RELEASE.jar!/:2.1.9.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.startWebServer(ServletWebServerApplicationContext.java:297) [spring-boot-2.1.9.RELEASE.jar!/:2.1.9.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.finishRefresh(ServletWebServerApplicationContext.java:163) [spring-boot-2.1.9.RELEASE.jar!/:2.1.9.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:552) [spring-context-5.1.10.RELEASE.jar!/:5.1.10.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141) [spring-boot-2.1.9.RELEASE.jar!/:2.1.9.RELEASE]

at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:744) [spring-boot-2.1.9.RELEASE.jar!/:2.1.9.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:391) [spring-boot-2.1.9.RELEASE.jar!/:2.1.9.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:312) [spring-boot-2.1.9.RELEASE.jar!/:2.1.9.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215) [spring-boot-2.1.9.RELEASE.jar!/:2.1.9.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1204) [spring-boot-2.1.9.RELEASE.jar!/:2.1.9.RELEASE]
at com.leapanalysis.apis.application.LAApplication.main(LAApplication.java:33) [classes!/:0-SNAPSHOT]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_222]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_222]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_222]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_222]
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48) [apis.jar:0-SNAPSHOT]
at org.springframework.boot.loader.Launcher.launch(Launcher.java:87) [apis.jar:0-SNAPSHOT]
at org.springframework.boot.loader.Launcher.launch(Launcher.java:51) [apis.jar:0-SNAPSHOT]
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:52) [apis.jar:0-SNAPSHOT]
but has failed to stop it. This is very likely to create a memory leak. Stack trace of
APPLICATION FAILED TO START
Description
The Tomcat connector configured to listen on port 8181 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 8181, or configure this application to listen on another port.

下图是我的Yaml文件

server:
port: 8181
ssl:
enabled: true
key-alias: tomcat
key-password: tomcat
key-store-password: tomcat
key-store: classpath:keystore.p12
key-store-type: PKCS12

我已经尝试了stackoverflow中几乎所有的答案
我试过的一些答案如下:

这仅在运行 jar 文件时发生,我可以轻松地从 IDE(我使用 Intellij)运行 spring boot 应用程序

  • 将端口从 8181 更改为 8443(还有许多其他端口)
  • 运行 jar 文件时明确指定服务器端口 (java -jar --server.port=8661)

  • 创建并尝试了 JKS 和 PKCS12 文件(运气不好)

  • 我使用 netsat -nltp | 检查端口中是否有任何其他应用程序正在运行 | grep :(此处未列出任何应用程序)- 也在 root 中检查了相同的命令,但未列出任何内容

  • 这只会在指定 ssl 文件时发生,如果 yaml 文件中没有 ssl 详细信息,应用程序很容易启动。

感谢任何帮助。提前致谢

最佳答案

我终于解决了这个问题!这是在 spring boot 版本 2.1.9.RELEASE 中使用的嵌入式 tomcat 版本 (9.0.25) 的问题。

我降级到 spring boot 2.1.8.RELEASE 并且它可以工作。更多详情:https://github.com/spring-projects/spring-boot/issues/18505

关于java - 无法使用 SSL 运行 Spring Boot 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58571984/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com