springboot項目不占用端口啟動
現在很多互聯網公司或者項目,都使用springboot + springcloud,以微服務的形式來提供后臺服務。而且既然是微服務,所涉及到的項目就會很多,服務器端口資源就會相當緊張。而且,其實有些項目,如定時任務等,是不需要對外提供服務,也就不需要占用服務器端口的。那么,在springboot項目中,怎么實現呢?其實很簡單,如下:
1
2
3
4
5
6
7
8
|
@enablescheduling @springbootapplication public class application { public static void main(string[] args) { new springapplicationbuilder().sources(application. class ).web( false ).run(args); } } |
這樣,項目可以正常啟動,而且,這個項目是不占用端口的。一般適用于定時任務項目。
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
1
2
3
4
5
6
7
8
9
|
@springbootapplication public class springbootdisablewebenvironmentapplication { public static void main(string[] args) { new springapplicationbuilder(springbootdisablewebenvironmentapplication . class ) .web(webapplicationtype.none) // .reactive, .servlet .run(args); } } |
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持服務器之家。
原文鏈接:https://my.oschina.net/u/2617082/blog/1924985