<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的項目如何打成war包

          共 3400字,需瀏覽 7分鐘

           ·

          2020-10-29 23:59

          點擊上方藍色字體,選擇“標星公眾號”

          優(yōu)質文章,第一時間送達

          ? 作者?|??別先生

          來源 |? urlify.cn/22qeAn

          66套java從入門到精通實戰(zhàn)課程分享

          1、在SpringBoot中默認支持Tomcat容器,所以當一個SpringBoot項目打包生成*.jar文件,并且直接執(zhí)行的時候就會自動啟動內部的Tomcat容器。除了此種模式之外,也可以將Web項目打包為*.war文件,采用部署的形式通過Tomcat進行發(fā)布處理,這種方式和傳統(tǒng)模式比較類似,打成war包丟到tomcat里面進行運行。

          ?

          2、在將SpringBoot打包為*.war文件的時候,如果想正常部署一定要注意以下兩點:

            第一點:是取消項目中的Jetty容器的配置。

            第二點:是將所有的源文件夾目錄設置輸出資源,修改父pom.xml中的配置。千萬注意,創(chuàng)建WEB-INF/web.xml配置文件,不然會提示報錯的哦。

          ?

          3、開始修改pom.xml配置文件,將程序的打包類型定義為*.war,修改pom.xml配置文件,追加war文件打包插件。

          "1.0"?>
          ????xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
          ????http://maven.apache.org/xsd/maven-4.0.0.xsd"

          ????xmlns="http://maven.apache.org/POM/4.0.0"
          ????xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
          ????4.0.0

          ????
          ????????com.bie
          ????????springboot-base
          ????????0.0.1-SNAPSHOT
          ????


          ????
          ????
          ????springboot-tentent
          ????
          ????springboot-tentent
          ????http://maven.apache.org
          ????
          ????war

          ????
          ????????UTF-8
          ????


          ????
          ????????
          ????????????org.springframework.boot
          ????????????spring-boot-starter-web
          ????????

          ????????
          ????????????org.springframework.boot
          ????????????spring-boot-starter-test
          ????????????test
          ????????

          ????????
          ????????????junit
          ????????????junit
          ????????????test
          ????????

          ????????
          ????????????org.springframework.boot
          ????????????spring-boot-starter-jetty
          ????????

          ????


          ????
          ????????
          ????????????
          ????????????
          ????????????????org.springframework.boot
          ????????????????spring-boot-maven-plugin
          ????????????????
          ????????????????
          ????????????????????org.springboot.tentent.Springboot01Application
          ????????????????

          ????????????????
          ????????????????????
          ????????????????????????
          ????????????????????????????repackage
          ????????????????????????

          ????????????????????

          ????????????????

          ????????????

          ????????????
          ????????????????org.apache.maven.plugins
          ????????????????maven-war-plugin
          ????????????????
          ????????????????????
          ????????????????????springboot-tentent
          ????????????????

          ????????????

          ????????

          ????????
          ????????????
          ????????????????src/main/resources
          ????????????????
          ????????????????????**/*.properties
          ????????????????????**/*.yml
          ????????????????????**/*.xml
          ????????????????????**/*.tld
          ????????????????

          ????????????????false
          ????????????

          ????????????
          ????????????????src/main/java
          ????????????????
          ????????????????????**/*.properties
          ????????????????????**/*.xml
          ????????????????????**/*.tld
          ????????????????

          ????????????????false
          ????????????

          ????????

          ????




          修改完pom.xml文件之后,更新項目會報錯提示缺少web.xml配置文件,此時創(chuàng)建一個web.xml配置文件即可。

          如果現(xiàn)在項目要以Tomcat的形式運行,那么需要修改SpringBoot程序啟動類定義,該類必須要繼承SpringBootServletInitializer父類,同時還需要覆寫configure()方法。?

          package?org.springboot.tentent;

          import?org.springframework.boot.SpringApplication;
          import?org.springframework.boot.autoconfigure.SpringBootApplication;
          import?org.springframework.boot.builder.SpringApplicationBuilder;
          import?org.springframework.boot.web.servlet.support.SpringBootServletInitializer;

          @SpringBootApplication?//?啟動Springboot程序,自帶子包掃描
          public?class?Springboot01Application?extends?SpringBootServletInitializer?{

          ????@Override
          ????protected?SpringApplicationBuilder?configure(SpringApplicationBuilder?builder)?{
          ????????//?配置Springboot的應用環(huán)境
          ????????SpringApplicationBuilder?sources?=?builder.sources(Springboot01Application.class);
          ????????return?sources;
          ????}

          ????public?static?void?main(String[]?args)?{
          ????????SpringApplication.run(Springboot01Application.class,?args);
          ????}

          }

          對項目進行打包部署(clean package),成功之后會在target目錄中形成xxx.war程序文件,隨后可以將此文件直接復制到Tomcat所在目錄之中,而后啟動Tomcat進行項目發(fā)布。

          生成的xxx.war包在target目錄下面,由于我的使用的maven創(chuàng)建父子工程,所以生成了兩個,如下所示:

          此時可以將此文件直接復制到Tomcat所在目錄(apache-tomcat-8.5.34\webapps)之中,而后啟動Tomcat進行項目發(fā)布。?




          粉絲福利:實戰(zhàn)springboot+CAS單點登錄系統(tǒng)視頻教程免費領取

          ???

          ?長按上方微信二維碼?2 秒
          即可獲取資料



          感謝點贊支持下哈?

          瀏覽 72
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

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

          手機掃一掃分享

          分享
          舉報
          <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>
                  夜夜干天天干 | 操熟女91| 玖玖热这里只有精品 | 大尺度一区 | 亚洲精品乱码久久久久久9色 |