SpringBoot项目不占用端口启动的方法
SpringBoot项目不占用端口启动
现在很多互联网公司或者项目,都使用SpringBoot+SpringCloud,以微服务的形式来提供后台服务。而且既然是微服务,所涉及到的项目就会很多,服务器端口资源就会相当紧张。而且,其实有些项目,如定时任务等,是不需要对外提供服务,也就不需要占用服务器端口的。那么,在SpringBoot项目中,怎么实现呢?其实很简单,如下:
@EnableScheduling
@SpringBootApplication
publicclassApplication{
publicstaticvoidmain(String[]args){
newSpringApplicationBuilder().sources(Application.class).web(false).run(args);
}
}
这样,项目可以正常启动,而且,这个项目是不占用端口的。一般适用于定时任务项目。
StartingfromSpringBoot2.0
-web(false)/setWebEnvironment(false)isdeprecatedandinsteadWeb-Application-Typecanbeusedtospecify
spring.main.web-application-type=NONE
@SpringBootApplication
publicclassSpringBootDisableWebEnvironmentApplication{
publicstaticvoidmain(String[]args){
newSpringApplicationBuilder(SpringBootDisableWebEnvironmentApplication.class)
.web(WebApplicationType.NONE)//.REACTIVE,.SERVLET
.run(args);
}
}
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。
热门推荐
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短