<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    java學習

    java學習

     

    soringboot項目大war包,部署到Tomcat步驟

    springboot的應用打包默認是打成jar包,并且如果是web應用的話,默認使用內置的tomcat充當servlet容器,但畢竟內置的tomcat有時候并不滿足我們的需求,如有時候我們想集群或者其他一些特性優化配置,因此我們需要把springboot的jar應用打包成war包,并能夠在外部tomcat中運行。
        很多人會疑問,你直接打成war包并部署到tomcat的webapp下不就行了么?No,springboot的如果在類路徑下有tomcat相關類文件,就會以內置tomcat啟動的方式,經過你把war包扔到外置的tomcat的webapp文件下啟動springBoot應用也無事于補。
        要把springboot應用轉至外部tomcat的操作主要有以下三點:
    1、把pom.xml文件中打包結果由jar改成war,如下:
    [html] view plain copy
    1. <modelVersion>4.0.0</modelVersion>  
    2. <groupId>spring-boot-panminlan-mybatis-test</groupId>  
    3. <artifactId>mybatis-test</artifactId>  
    4. <packaging>war</packaging>  
    5. <version>0.0.1-SNAPSHOT</version>  

    2、添加maven的war打包插件如下:并且給war包起一個名字,tomcat部署后的訪問路徑會需要,如:http:localhost:8080/myweb/****

      
    [java] view plain copy
    1. <plugin>       
    2.    <groupId>org.apache.maven.plugins</groupId>       
    3.    <artifactId>maven-war-plugin</artifactId>       
    4.    <configuration>       
    5.     <warSourceExcludes>src/main/resources/**</warSourceExcludes>  
    6.     <warName>myweb</warName>       
    7.    </configuration>       
    8.   </plugin>       

    3、排除org.springframework.boot依賴中的tomcat內置容器,這是很重要的一步

    [java] view plain copy
    1. <dependency>  
    2.         <groupId>org.springframework.boot</groupId>  
    3.         <artifactId>spring-boot-starter-web</artifactId>  
    4.         <exclusions>  
    5.             <exclusion>  
    6.                 <groupId>org.springframework.boot</groupId>  
    7.                 <artifactId>spring-boot-starter-tomcat</artifactId>  
    8.             </exclusion>  
    9.         </exclusions>  
    10.     </dependency>  

    4、添加對servlet API的依賴
    [java] view plain copy
    1. <dependency>  
    2.             <groupId>javax.servlet</groupId>  
    3.             <artifactId>javax.servlet-api</artifactId>  
    4.         </dependency>  

    5、繼承SpringBootServletInitializer ,并覆蓋它的 configure 方法,如下圖代碼,為什么需要提供這樣一個SpringBootServletInitializer子類并覆蓋它的config方法呢,我們看下該類原代碼的注釋:
    /**Note that a WebApplicationInitializer is only needed if you are building a war file and
     * deploying it. If you prefer to run an embedded container then you won't need this at
     * all.
    如果我們構建的是wai包并部署到外部tomcat則需要使用它,如果使用內置servlet容器則不需要,外置tomcat環境的配置需要這個類的configure方法來指定初始化資源。
    [java] view plain co@SpringBootApplication
    //@ServletComponentScan
    public class JobManagementApplication extends SpringBootServletInitializer{

         @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
                return application.sources(JobManagementApplication.class);
            }
        public static void main(String[] args) {
            SpringApplication.run(JobManagementApplication.class, args);
        }
    }
    經過以上配置,我們把構建好的war包拷到tomcat的webapp下,啟動tomcat就可以訪問啦

    posted on 2018-03-17 18:39 楊軍威 閱讀(666) 評論(0)  編輯  收藏


    只有注冊用戶登錄后才能發表評論。


    網站導航:
     

    導航

    統計

    常用鏈接

    留言簿

    隨筆檔案

    搜索

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 亚洲国产成人综合精品| 中文字幕不卡免费高清视频| 在线观看永久免费视频网站| 一级毛片免费不卡直观看| 国产精品亚洲一区二区三区在线| 日日麻批免费40分钟日本的| 日韩亚洲翔田千里在线| 亚洲精品国产精品乱码不卡√ | 另类图片亚洲校园小说区| 国产亚洲av片在线观看16女人 | 亚洲图片在线观看| 麻豆国产入口在线观看免费| 免费精品一区二区三区第35| 亚洲中文字幕乱码熟女在线| 国产国拍亚洲精品mv在线观看 | 中国黄色免费网站| 最新国产成人亚洲精品影院| 亚洲午夜福利AV一区二区无码| 一个人在线观看视频免费| 中文在线免费不卡视频| 亚洲а∨精品天堂在线| 亚洲好看的理论片电影| 亚洲国产精品日韩| 最近中文字幕mv免费高清电影| 日韩电影免费在线观看| 污视频网站免费观看| 亚洲av专区无码观看精品天堂 | 亚洲JIZZJIZZ妇女| 久久国产亚洲高清观看| 亚洲国产成人精品无码久久久久久综合| 免费福利在线播放| 精品国产免费一区二区三区香蕉 | 啦啦啦高清视频在线观看免费 | 999久久久免费精品播放| 日韩电影免费在线观看网址| 精品国产成人亚洲午夜福利| 91在线亚洲精品专区| 国产亚洲精品国产| 在线精品亚洲一区二区小说| 四虎AV永久在线精品免费观看| 最新中文字幕免费视频|