Spring Boot 在同一端口上将 HTTP 重定向到 HTTPS

kam*_*aci 6 https spring tomcat http spring-boot

我有一个在 HTTPS 上运行的 Spring Boot 1.5.21 应用程序。我想将 HTTP 请求重定向到同一端口的 HTTPS。我application.yaml的如下:

server:
  port: 8443
  error:
    whitelabel:
      enabled:  false
  ssl:
    key-store:  classpath:keystore/tomcat.p12
    key-store-type: PKCS12
    key-store-password: password
    key-alias:  tomcat
Run Code Online (Sandbox Code Playgroud)

当我在 URL 栏中输入以下内容时:

http://localhost:8443
Run Code Online (Sandbox Code Playgroud)

我像往常一样看到这个错误:

Bad Request
This combination of host and port requires TLS.
Run Code Online (Sandbox Code Playgroud)

当我刷新页面时,不会发生。当我单击 URL 栏并在 Chrome 中再次单击 Enter 时,链接将被重定向。

我的问题:

  1. 我怎样才能使该网址:

http://localhost:8443

自动重定向到:

https://localhost:8443

  1. 如果以下内容不适用,我该如何删除该消息?

这里有一个类似的问题,要求不同的端口,并且答案不适用于我的情况: Spring Boot 将 HTTP 重定向到 HTTPS