application.properties中添加设置以下设置
#https证书
#修改默认端口号# https 加密端口号 443
server.port=${appPort:443}
#server.port=${appPort:8008}
server.additionalPorts=8008,8001//自定义属性可以为8008,8001,8003......添加任意
新建类xxxx (添加如下方法)
@Value("${server.additionalPorts}")
private String additionalPorts;
@Bean
public TomcatServletWebServerFactory servletContainer() {
TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory();
Connector[] additionalConnectors = this.additionalConnector();
if (additionalConnectors != null && additionalConnectors.length > 0) {
tomcat.addAdditionalTomcatConnectors(additionalConnectors);
}
return tomcat;
}
private Connector[] additionalConnector() {
if (this.additionalPorts==null) {//这里你可以修改成判断他的长度和是否等于null
return null;
}
String[] ports = this.additionalPorts.split(",");
List<Connector> result = new ArrayList<>();
for (String port : ports) {
Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
connector.setScheme("http");
connector.setPort(Integer.valueOf(port));
result.add(connector);
}
return result.toArray(new Connector[] {});
}
在TwentyfourfinnerApplication中添加上面新建类
@SpringBootApplication
@MapperScan("com.xxxx.xxx.dao")
@Import({HttsConfig.class})//添加新建的类
public class TwentyfourfinnerApplication {
public static void main(String[] args) {
SpringApplication.run(TwentyfourfinnerApplication.class, args);
System.out.println("后台启动成功");
}
}