springboot如何配置,同时支持https和http
1、配置springboo资源文件application.yml
http:
port: 18666 #服务端口
#https 配置
server:
port: 8002
ssl:
key-store: D:\test.keystore
enabled: true
key-store-password: 123456
key-store-type: JKS
2、启动类中添加
@Value("${http.port}")
private Integer port;
@Bean
public ServletWebServerFactory servletContainer() {
TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory();
// 配置http
Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
connector.setPort(port);
tomcat.addAdditionalTomcatConnectors(connector); // 添加http
return tomcat;
}
完整版如下图:
3、若资源文件中不显示申明server.port:端口号,则项目会默认以8080为http端口
结果呈现:
相关系列文章:
1.Https 生成证书添加至SpringBoot配置
2.Postman请求https接口配置
3.springboot如何配置,同时支持https和http
大家好,我是徐小慧
📢 博客主页:徐小慧_Blog
📢 欢迎 点赞 👍 | 收藏 ⭐ | 留言 📝 如有错误敬请指正!