Spring boot - 将 Tomcat HTTP 嵌入到 HTTPS 重定向

Spring boot - 将 Tomcat HTTP 嵌入到 HTTPS 重定向

问题描述:

我使用的是 Java 7、Spring-Boot 1.1.7 和嵌入式 Tomcat 7.

I'm using Java 7, Spring-Boot 1.1.7 and an ambeded Tomcat 7.

过去,当我使用独立的 Tomcat 时,我曾经添加一个 http 连接器,它将请求重定向到 HTTPS 端口:

In the past, when I used a stand alone Tomcat, I used to add an http connector, that will redirect the requests to the HTTPS port :

<Connector port="8080" enableLookups="false"
           redirectPort="8443" />

当我使用嵌入式 Tomcat(并且我没有 server.xml 文件)时,我该怎么做?

How can I do it when I'm using an embeded Tomcat (and I dont have a server.xml file) ?

您可以添加 Connector 或使用其 Java API 配置现有的连接器(例如,请参阅 http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#howto-enable-multiple-connectors-in-tomcat).Connector 有一个 setRedirectPort()(它由 XML <Connector/> 元素直接映射).

You can add a Connector or configure the existing one with its Java API (e.g. see http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#howto-enable-multiple-connectors-in-tomcat). The Connector has a setRedirectPort() (it's mapped directly by the XML <Connector/> element).