如今不少互聯網公司或者項目,都使用SpringBoot + SpringCloud,以微服務的形式來提供後臺服務。並且既然是微服務,所涉及到的項目就會不少,服務器端口資源就會至關緊張。並且,其實有些項目,如定時任務等,是不須要對外提供服務,也就不須要佔用服務器端口的。那麼,在SpringBoot項目中,怎麼實現呢?其實很簡單,以下:
web
@EnableScheduling @SpringBootApplication public class Application { public static void main(String[] args) { new SpringApplicationBuilder().sources(Application.class).web(false).run(args); } }
這樣,項目能夠正常啓動,並且,這個項目是不佔用端口的。通常適用於定時任務項目。
服務器