1. <strong id="7actg"></strong>
    2. <table id="7actg"></table>

    3. <address id="7actg"></address>
      <address id="7actg"></address>
      1. <object id="7actg"><tt id="7actg"></tt></object>

        Springboot的項(xiàng)目如何打成war包

        共 3400字,需瀏覽 7分鐘

         ·

        2020-10-29 23:59

        點(diǎn)擊上方藍(lán)色字體,選擇“標(biāo)星公眾號”

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

        ? 作者?|??別先生

        來源 |? urlify.cn/22qeAn

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

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

        ?

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

          第一點(diǎn):是取消項(xiàng)目中的Jetty容器的配置。

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

        ?

        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文件之后,更新項(xiàng)目會報(bào)錯提示缺少web.xml配置文件,此時創(chuàng)建一個web.xml配置文件即可。

        如果現(xiàn)在項(xiàng)目要以Tomcat的形式運(yùn)行,那么需要修改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的應(yīng)用環(huán)境
        ????????SpringApplicationBuilder?sources?=?builder.sources(Springboot01Application.class);
        ????????return?sources;
        ????}

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

        }

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

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

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




        粉絲福利:實(shí)戰(zhàn)springboot+CAS單點(diǎn)登錄系統(tǒng)視頻教程免費(fèi)領(lǐng)取

        ???

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



        感謝點(diǎn)贊支持下哈?

        瀏覽 72
        點(diǎn)贊
        評論
        收藏
        分享

        手機(jī)掃一掃分享

        分享
        舉報(bào)
        評論
        圖片
        表情
        推薦
        點(diǎn)贊
        評論
        收藏
        分享

        手機(jī)掃一掃分享

        分享
        舉報(bào)
        1. <strong id="7actg"></strong>
        2. <table id="7actg"></table>

        3. <address id="7actg"></address>
          <address id="7actg"></address>
          1. <object id="7actg"><tt id="7actg"></tt></object>
            黄色操B视频 | 欧美日韩三级片在线观看 | 日韩无码中文字幕电影 | 日骚逼视频 | 操骚逼网站| 国产精品久久久久久久妇女 | 男女爱爱免费网站 | 色欲av伊人久久大香线蕉影院 | 熟女吊钟嗷嗷叫91 | 日韩做爱网站 |