欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

SpringBoot項(xiàng)目不占用端口啟動(dòng)的方法

 更新時(shí)間:2018年08月16日 10:55:33   作者:Jetyang  
這篇文章主要介紹了SpringBoot項(xiàng)目不占用端口啟動(dòng)的方法,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧

SpringBoot項(xiàng)目不占用端口啟動(dòng)

現(xiàn)在很多互聯(lián)網(wǎng)公司或者項(xiàng)目,都使用SpringBoot + SpringCloud,以微服務(wù)的形式來(lái)提供后臺(tái)服務(wù)。而且既然是微服務(wù),所涉及到的項(xiàng)目就會(huì)很多,服務(wù)器端口資源就會(huì)相當(dāng)緊張。而且,其實(shí)有些項(xiàng)目,如定時(shí)任務(wù)等,是不需要對(duì)外提供服務(wù),也就不需要占用服務(wù)器端口的。那么,在SpringBoot項(xiàng)目中,怎么實(shí)現(xiàn)呢?其實(shí)很簡(jiǎn)單,如下:

@EnableScheduling
@SpringBootApplication
public class Application {

 public static void main(String[] args) {
 new SpringApplicationBuilder().sources(Application.class).web(false).run(args);
 }
}

這樣,項(xiàng)目可以正常啟動(dòng),而且,這個(gè)項(xiàng)目是不占用端口的。一般適用于定時(shí)任務(wù)項(xiàng)目。

Starting from Spring Boot 2.0

-web(false)/setWebEnvironment(false) is deprecated and instead Web-Application-Type can be used to specify
spring.main.web-application-type=NONE

@SpringBootApplication
public class SpringBootDisableWebEnvironmentApplication {

  public static void main(String[] args) {
    new SpringApplicationBuilder(SpringBootDisableWebEnvironmentApplication .class)
      .web(WebApplicationType.NONE) // .REACTIVE, .SERVLET
      .run(args);
  }
}

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論