springboot https使用p12文件

使用springboot创建了一个很小的项目,可以运行

现将其改为https访问,申请了域名和证书,
获取了crt文件并用openssl命令生成了p12文件

最后将其与配置放入项目中
application.properties:

server.port:80
server.ssl.key-store=classpath:xxx.p12
server.ssl.key-store-password=xxx
server.ssl.keyStoreType=PKCS12
// server.ssl.keyAlias=tomcat

可以在intellij中运行,但是生成的jar包总是报错端口被占用。
报错部分:

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-07-31 12:15:46.565 ERROR 5952 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter
 :

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

Description:

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

其实可以看到springboot已经启动了(有图标),只是最后报错。

  1. 测试发现不是端口问题,并且只要注释掉上述配置(port除外)就可以运行
  2. 在生成p12文件时只要求输入密码,并没有一个alias选项,不知是否为此原因
  3. key-store部分不知是否要加入classpath:,不过测试发现加不加都不行(p12文件就在当前目录中)

求解释什么问题

阅读 4.3k
1 个回答

https要配置加密端口,常用443或8443, 80为http协议的标准端口,用浏览器浏览80端口的https协议会报错的。
再有,配置application.properties不是冒号,而是要用等号

server.port=443

application.yml

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