package com.mzl.flower.config;
|
|
import org.apache.catalina.connector.Connector;
|
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
|
import org.springframework.boot.web.servlet.server.ServletWebServerFactory;
|
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Configuration;
|
|
//@Configuration
|
public class HttpRedirectConfig {
|
|
// @Value("${server.http.port}") // 从YAML中读取HTTP端口
|
private int httpPort;
|
|
@Bean
|
public ServletWebServerFactory servletContainer() {
|
TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory();
|
tomcat.addAdditionalTomcatConnectors(createHttpConnector());
|
return tomcat;
|
}
|
|
private Connector createHttpConnector() {
|
Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
|
connector.setScheme("http");
|
connector.setPort(httpPort);
|
connector.setSecure(false);
|
connector.setRedirectPort(8443); // 重定向到HTTPS端口
|
return connector;
|
}
|
}
|