亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Spring Boot將項(xiàng)目打包成war包的操作方法

 更新時(shí)間:2018年09月27日 16:36:54   作者:ycyzharry  
這篇文章主要介紹了Spring Boot將項(xiàng)目打包成war包的操作方法,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

1 修改項(xiàng)目打包類型

在pom.xml里,項(xiàng)目打包類型將jar設(shè)置成war:

<packaging>war</packaging>

2 移除內(nèi)置tomcat容器

在pom.xml里設(shè)置:

<dependencies>
    <!--web啟動器依賴-->
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
      <!--移除默認(rèn)啟動容器-->
      <exclusions>
        <exclusion>
          <artifactId>spring-boot-starter-tomcat</artifactId>
          <groupId>org.springframework.boot</groupId>
        </exclusion>
      </exclusions>
    </dependency>

3 添加servlet-api依賴

若項(xiàng)目的某些工具類會用到該依賴,如果缺失,會報(bào)錯(cuò):

/tool/WebUtil.java:[6,26] 程序包javax.servlet.http不存在

需要在pom.xml里添加如下依賴:

<dependency>  
    <groupId>javax.servlet</groupId>  
    <artifactId>javax.servlet-api</artifactId>  
    <version>3.1.0</version>  
    <scope>provided</scope>
</dependency>

或者下面依賴(任選其一):

<dependency>
  <groupId>org.apache.tomcat</groupId>
  <artifactId>tomcat-servlet-api</artifactId>
  <version>8.0.36</version>
  <scope>provided</scope>
</dependency>

4 修改項(xiàng)目啟動類

Spring Boot入口類必須實(shí)現(xiàn)SpringBootServletInitializer接口的configure方法才能讓外部容器運(yùn)行Spring Boot項(xiàng)目。

原入口類MainApplication.java內(nèi)容如下:

package com.maxbill;
import com.maxbill.core.desktop.DesktopApp;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.context.ConfigurableApplicationContext;
@SpringBootApplication
@MapperScan("com.maxbill.base.dao")
public class MainApplication extends DesktopApp {
  public static ConfigurableApplicationContext context;
  public static void main(String[] args) {
    //啟動后臺服務(wù)
    context = SpringApplication.run(MainApplication.class, args);
    //啟動桌面服務(wù)
    launch(args);
  }
}

修改后內(nèi)容如下:

package com.maxbill;
import com.maxbill.core.desktop.DesktopApp;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;    
import org.springframework.boot.builder.SpringApplicationBuilder;
@SpringBootApplication
@MapperScan("com.maxbill.base.dao")
public class MainApplication extends SpringBootServletInitializer{
  @Override
  //修改啟動類,繼承 SpringBootServletInitializer并重寫 configure方法
  protected SpringApplicationBuilder configure(SpringApplicationBuilder builder){
    //注意這里要指向原先用main方法執(zhí)行的Application啟動類
    return builder.sources(MainApplication.class);
  }
  public static ConfigurableApplicationContext context;
  public static void main(String[] args) {
    //啟動后臺服務(wù)
    context = SpringApplication.run(MainApplication.class, args);
    //啟動桌面服務(wù)
    launch(args);
  }
}

5 打包部署項(xiàng)目

maven執(zhí)行命令跳過測試打包

mvn clean package -DskipTests

build信息如下

[INFO] Building war: D:\Workspace\MaxBill-RedisPlus-master\RedisPlus\target\RedisPlus-0.0.1-SNAPSHOT.war
[INFO]
[INFO] --- spring-boot-maven-plugin:2.0.4.RELEASE:repackage (default) @ RedisPlus ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------

build成功后,在項(xiàng)目target目錄下把war包部署到tomcat的webapps目錄下,例如:

D:\Program Files\Apache Software Foundation\Tomcat 8.0\webapps

啟動tomcat服務(wù),在瀏覽器訪問

http://localhost:[端口號]/[打包項(xiàng)目名]/

總結(jié)

以上所述是小編給大家介紹的Spring Boot將項(xiàng)目打包成war包的操作方法,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時(shí)回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!

相關(guān)文章

  • Springboot創(chuàng)建子父工程過程圖解

    Springboot創(chuàng)建子父工程過程圖解

    這篇文章主要介紹了Springboot創(chuàng)建子父工程過程圖解,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-02-02
  • Java實(shí)現(xiàn)Fibonacci(斐波那契)取余的示例代碼

    Java實(shí)現(xiàn)Fibonacci(斐波那契)取余的示例代碼

    這篇文章主要介紹了Java實(shí)現(xiàn)Fibonacci取余的示例代碼,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-03-03
  • java實(shí)現(xiàn)訂餐系統(tǒng)

    java實(shí)現(xiàn)訂餐系統(tǒng)

    這篇文章主要為大家詳細(xì)介紹了java實(shí)現(xiàn)訂餐系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-07-07
  • QR 二維碼中插入圖片實(shí)現(xiàn)方法

    QR 二維碼中插入圖片實(shí)現(xiàn)方法

    這篇文章主要介紹了QR 二維碼中插入圖片實(shí)現(xiàn)方法的相關(guān)資料,需要的朋友可以參考下
    2016-11-11
  • Java使用Instant時(shí)輸出的時(shí)間比預(yù)期少了八個(gè)小時(shí)

    Java使用Instant時(shí)輸出的時(shí)間比預(yù)期少了八個(gè)小時(shí)

    在Java中,LocalDateTime表示沒有時(shí)區(qū)信息的日期和時(shí)間,而Instant表示基于UTC的時(shí)間點(diǎn),本文主要介紹了Java使用Instant時(shí)輸出的時(shí)間比預(yù)期少了八個(gè)小時(shí)的問題解決,感興趣的可以了解一下
    2024-09-09
  • 基于SpringBoot+Redis實(shí)現(xiàn)分布式鎖

    基于SpringBoot+Redis實(shí)現(xiàn)分布式鎖

    本文主要介紹了基于SpringBoot+Redis實(shí)現(xiàn)分布式鎖,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-05-05
  • Spring中BeanFactory與FactoryBean接口的區(qū)別詳解

    Spring中BeanFactory與FactoryBean接口的區(qū)別詳解

    這篇文章主要給大家介紹了關(guān)于Spring中BeanFactory與FactoryBean接口的區(qū)別的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者使用Spring具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-03-03
  • 為什么SpringBoot的jar可以直接運(yùn)行

    為什么SpringBoot的jar可以直接運(yùn)行

    這篇文章主要介紹了為什么SpringBoot的jar可以直接運(yùn)行,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-05-05
  • Java編程訪問權(quán)限的控制代碼詳解

    Java編程訪問權(quán)限的控制代碼詳解

    這篇文章主要介紹了Java編程訪問權(quán)限的控制代碼詳解,涉及包名,公共的和私有的等相關(guān)內(nèi)容,分享了相關(guān)代碼示例,小編覺得還是挺不錯(cuò)的,具有一定借鑒價(jià)值,需要的朋友可以參考下
    2018-01-01
  • Java Class.forName()用法和newInstance()方法原理解析

    Java Class.forName()用法和newInstance()方法原理解析

    這篇文章主要介紹了Java Class.forName()用法和newInstance()方法原理解析,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-08-08

最新評論