配置文件
server:
port: 4000
https:
port: 8443
ssl:
key-store: classpath:sample.jks
key-store-password: secret
key-password: password
启动文件配置:
@SpringBootApplication
public class SampleTomcatTwoConnectorsApplication {
@Value("${http.port}")
private Integer port;
/* --------------------请按照自己spring boot版本选择 start--------------------- */
// 这是spring boot 1.5.X以下版本的 添加了这个,下一个就不用添加了
@Bean
public EmbeddedServletContainerFactory servletContainer() {
TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory();
tomcat.addAdditionalTomcatConnectors(createStandardConnector()); // 添加http
return tomcat;
}
// 这是spring boot 2.0.X版本的 添加这个,上一个就不用添加了
@Bean
public ServletWebServerFactory servletContainer() {
TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory();
tomcat.addAdditionalTomcatConnectors(createStandardConnector()); // 添加http
return tomcat;
}
/* --------------------请按照自己spring boot版本选择 end--------------------- */
// 配置http
private Connector createStandardConnector() {
Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
connector.setPort(port);
return connector;
}
public static void main(String[] args) throws Exception {
SpringApplication.run(SampleTomcatTwoConnectorsApplication.class, args);
}
}
网友评论