<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          面試官:你能說出Springboot項目啟動的幾種方式嗎?

          共 2101字,需瀏覽 5分鐘

           ·

          2020-09-19 08:47

          點擊上方“JAVA”,星標公眾號

          重磅干貨,第一時間送達
          spring-boot的啟動方式主要有三種:
          1. 運行帶有main方法類
          2. 通過命令行 java -jar 的方式
          3. 通過spring-boot-plugin的方式

          一、執(zhí)行帶有main方法類

          這種方式很簡單,我主要是通過idea的方式,進行執(zhí)行。這種方式在啟動的時候,會去自動加載classpath下的配置文件

          (這里只是單獨的強調(diào)了classpath下,其實spring-boot有自己的加載路徑和優(yōu)先級的,日后在發(fā)布).

          @RestController
          @EnableAutoConfiguration
          public?class?Example?{
          ?
          ????@RequestMapping("/")
          ????public?String?home()?{
          ????????return?"Hello?World";
          ????}
          ?
          ????public?static?void?main(String[]?args)?{
          ????????/**
          ?????????*?SpringApplication會自動加載application.properties文件,具體的加載路徑包含以下:
          ?????????*?


          ?????????*?????1.?A?/config?subdirectory?of?the?current?directory;
          ?????????*?????


          ?????????*?


          ?????????*?????2.?The?Current?Directory
          ?????????*?


          ?????????*?


          ?????????*?????3.?A?classpath?/config?package
          ?????????*?


          ?????????*?


          ?????????*?????4.?The?classpath?root.
          ?????????*?


          ?????????*/

          ????????SpringApplication.run(Example.class,?args);
          ????}
          }

          在idea中,可以通過配置application的方式配置上自己請求參數(shù)

          二、通過java -jar的方式

          java?-jar?jar_path?--param

          jar_path: 指代將項目打包為jar打包之后的存儲路徑

          --param: 為需要在命令行指定的參數(shù)。例如:

          java?-jar?emample.jar?--server.port=8081

          該命令通過在啟動行指定了項目啟動后綁定的端口號,因為該命令行參數(shù),將會覆蓋application.properties中的端口配置

          三、通過spring-boot-plugin方式啟動

          如果需要正常使用該maven查件,需要我們在maven項目中增加以下插件配置:

          <plugin>?
          ??<groupId>org.springframework.bootgroupId>??
          ??<artifactId>spring-boot-maven-pluginartifactId>??
          ????
          ????
          ????
          ????
          ????
          ????
          ????
          ???
          plugin>

          注: 因為我在項目中指定了父模塊 spring-boot-starter-parent。因此我不需要單獨指定插件版本,該父模塊會自動匹配與當前spring-boot版本相匹配的查件版本。

          <parent>
          ????????<groupId>org.springframework.bootgroupId>
          ????????<artifactId>spring-boot-starter-parentartifactId>
          ????????<version>1.5.10.RELEASEversion>
          ?
          ????????
          ????????
          ????????
          ????parent>

          準備工作做好之后,我們需要進入項目的根目錄,執(zhí)行

          mvn?spring-boot:run

          該命令能夠正常啟動項目,但是如何為其指定執(zhí)行參數(shù)呢?

          spring-boot:run該maven查件在插件首頁中指定了相關(guān)能夠使用的可選參數(shù):

          通過查閱文檔,可以通過命令的方式查看具體選項的意義以及用法:

          mvn?spring-boot:help?-Ddetail

          其中arguments的描述中,大意為:指定的參數(shù)會傳遞給具體應(yīng)用,如果有多個參數(shù)需要指定,以","進行分割。具體用法通過run.arguments來指定:

          mvn?spring-boot:run?-Drun.arguments="--server.port=8888"

          來源:blog.csdn.net/u011425751/article/details/79507386

          更多精彩?


          在公眾號【程序員編程】對話框輸入以下關(guān)鍵詞
          查看更多優(yōu)質(zhì)內(nèi)容!

          大數(shù)據(jù)?|?Java?|?1024?|?電子書?|?速查表?
          Python進階?|?面試?|?手冊?|?成神?|?思想?|?小程序
          命令行?|?人工智能?|?軟件測試?|?Web前端?|?Python

          掃碼關(guān)注我們

          獲取更多學習資料

          視頻 |?面試 |?技術(shù) | 電子書?

          瀏覽 30
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          分享
          舉報
          評論
          圖片
          表情
          推薦
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          分享
          舉報
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  伊人永久在线 | 国产欧美一区二区精品性色超碰 | 天天日天天干天天胔 | 亚州成人娱乐网 | 欧美性开放网站 |