2017-03-20 18 views
-1

我有一個spring引導項目,我希望它能夠作爲控制檯啓動,如果參數指示如此,否則,它將從嵌入式tomcat開始。您可以考慮如果應用程序作爲控制檯啓動,那麼當您鍵入「狀態」時,它將在控制檯中回覆「正常」。如果你輸入「退出」,應用程序將終止。當它作爲網絡應用程序啓動時,則當您訪問網址「http://localhost/stats」時,它將作爲頁面顯示「很好」。當你終止tomcat時,這意味着「退出」。有人知道如何寫主班嗎?可以通過傳遞參數來啓動Spring應用程序作爲控制檯還是作爲嵌入式tomcat的Web應用程序啓動?

回答

1
public static void main(String[] args) { 
     if (args.length > 0 && args[0].equalsIgnoreCase("web")) 
      SpringApplication.run(CommServerStarter.class, args); 
     else 
      startConsole(args); 
    } 

    public static void startConsole(String[] args) { 
     ... 
    } 
} 
相關問題