https后的Spring启动:配置为侦听端口8444的Tomcat连接器无法启动.

cbl*_*bll 10 java spring tomcat spring-mvc

我按照指南在Spring Boot中启用了https.该应用程序预先在https:// localhost:8080上工作

我创建了一个keystore.jks与my相同的目录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
Run Code Online (Sandbox Code Playgroud)

现在,如果我运行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.
Run Code Online (Sandbox Code Playgroud)

端口未使用,因此必须配置错误?

我不确定要改变什么.它是一个简单的SPA应用程序,Spring只提供index.html并且只有一个REST端点.在这种情况下,如何将tomcat/spring配置为接受https,并启动时没有错误?

Joh*_*hna 10

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

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

openssl pkcs12 -export -in <mycert.crt> -inkey <mykey.key> -out keystore.p12 -name <alias>
Run Code Online (Sandbox Code Playgroud)

系统将提示您输入密码,您可以输入密码.生成密钥库文件后,将其复制到文件所在的目录.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>
Run Code Online (Sandbox Code Playgroud)

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


Rut*_*wik 5

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

# 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
Run Code Online (Sandbox Code Playgroud)

我删除了别名,它工作得很好。“您可能不需要密钥别名,因为只有一个密钥条目”来自 TOMCAT SSL 错误:别名不能识别密钥条目