https 后的 Spring boot:配置为侦听端口 8444 的 Tomcat 连接器启动失败。

新手上路,请多包涵

我按照指南在 Spring Boot 中启用 https。该应用程序事先在 https://localhost:8080 上运行

我创建了一个 keystore.jks 与我的 application.properties 在同一目录中,现在看起来像:

 # Define a custom port instead of the default 8080
server.port = 8444
# Tell Spring Security (if used) to require requests over HTTPS
security.require-ssl=true
# The format used for the keystore
server.ssl.key-store-type:PKCS12
# The path to the keystore containing the certificate
server.ssl.key-store=keystore.p12
# The password used to generate the certificate
server.ssl.key-store-password=<somepassword>
# The alias mapped to the certificate
server.ssl.key-alias=tomcat

现在,如果我运行 main 方法来启动 spring boot 应用程序,它会抛出:

 Description:

The Tomcat connector configured to listen on port 8444 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 8444, or configure this application to listen on another port.

该端口未被使用,所以它一定是配置错误?

我不确定要更改什么。这是一个简单的 SPA 应用程序,Spring 仅提供一个 index.html 并具有一个 REST 端点。在这种情况下,tomcat/spring 应该如何配置才能接受https,并且启动不报错呢?

原文由 cbll 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 854
2 个回答

我也有同样的问题并且能够解决它。我的问题是生成 keystore.p12 文件。

如果您有证书文件和私钥文件,则可以使用以下命令生成 keystore.p12 文件。

 openssl pkcs12 -export -in <mycert.crt> -inkey <mykey.key> -out keystore.p12 -name <alias>

系统将提示您输入密码,您可以在此处输入您喜欢的密码。生成密钥库文件后,将其复制到 .jar 文件所在的目录。

以下是一个工作示例配置。

 server.port=8443
security.require-ssl=true
server.ssl.key-store-type=PKCS12
server.ssl.key-store=file:keystore.p12
server.ssl.key-store-password=<password>
server.ssl.key-alias=<alias>

请注意密钥存储文件路径 file:keystore.p12 如果它与可执行文件位于同一目录中 .jar 文件。

原文由 Johna 发布,翻译遵循 CC BY-SA 3.0 许可协议

我通过使用以下配置解决了同样的问题

# Define a custom port instead of the default 8080
server.port=8443
# Tell Spring Security (if used) to require requests over HTTPS
security.require-ssl=true
# The format used for the keystore
server.ssl.key-store-type=PKCS12
# The path to the keystore containing the certificate
server.ssl.key-store=src/main/resources/keystore.p12
# The password used to generate the certificate
server.ssl.key-store-password=root0

我删除了别名,它工作得很好。 “您可能不需要密钥别名,因为只有一个密钥条目”引用自 TOMCAT SSL Error: Alias name does not identify a key entry

原文由 Ruthwik 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题