springboot 同时启用http/https
1. 启用HTTPS
修改配置
- application.yml
server:
# port: 80
port: 443
ssl:
enabled: true
key-store: /key_store.jks
key-store-password: key_store_pwd
2. 添加http协议连接器
增加JAVA配置
@Bean
public ServletWebServerFactory servletWebServerFactory() {
TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory();
Connector connector = new Connector(TomcatServletWebServerFactory.DEFAULT_PROTOCOL);
connector.setPort(80);
tomcat.addAdditionalTomcatConnectors(connector);
return tomcat;
}