我按照指南在 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 许可协议
我也有同样的问题并且能够解决它。我的问题是生成
keystore.p12
文件。如果您有证书文件和私钥文件,则可以使用以下命令生成
keystore.p12
文件。系统将提示您输入密码,您可以在此处输入您喜欢的密码。生成密钥库文件后,将其复制到
.jar
文件所在的目录。以下是一个工作示例配置。
请注意密钥存储文件路径
file:keystore.p12
如果它与可执行文件位于同一目录中.jar
文件。