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

SpringBoot中打war包需要注意事項(xiàng)

 更新時(shí)間:2020年09月10日 09:33:38   作者:Asurplus、  
這篇文章主要介紹了SpringBoot中打war包需要注意事項(xiàng),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

最近在做一個(gè)項(xiàng)目,遇到了項(xiàng)目打成 war 包的一個(gè)問題,項(xiàng)目創(chuàng)建時(shí)選擇的時(shí) jar 包方式,后因項(xiàng)目部署要求,需要打成 war 包部署,遇到很多坑,在此做一下記錄

一、修改打包方式

原:

<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

改后:

<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>

二、排除內(nèi)置 Tomcat

原:

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-web</artifactId>
</dependency>

改后:

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-web</artifactId>
  <exclusions>
    <exclusion>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-tomcat</artifactId>
    </exclusion>
  </exclusions>
</dependency>

使用 排除內(nèi)置服務(wù)器

三、添加 Tomcat 依賴

用于編譯和測試開發(fā),兩種方式

1、

<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-tomcat</artifactId>
   <!-- 該包只在編譯和測試的時(shí)候使用 -->
  <scope>provided</scope>
</dependency>

2、

<dependency>
  <groupId>org.apache.tomcat</groupId>
  <artifactId>tomcat-servlet-api</artifactId>
  <version>8.5.34</version>
  <!-- 該包只在編譯和測試的時(shí)候使用 -->
  <scope>provided</scope>
</dependency>

四、改變項(xiàng)目的構(gòu)造方式

原:

<build>
  <plugins>
    <plugin>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-maven-plugin</artifactId>
    </plugin>
  </plugins>
</build>

改后:

<build>
	<!-- 一般為你的項(xiàng)目名,與配置文件中的context-path保持一致 -->
  <finalName>demo</finalName>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-compiler-plugin</artifactId>
      <configuration>
        <source>${java.version}</source>
        <target>${java.version}</target>
      </configuration>
    </plugin>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-war-plugin</artifactId>
      <configuration>
        <webResources>
          <resource>
            <directory>src/main/resources/lib</directory>
            <targetPath>WEB-INF/lib/</targetPath>
            <includes>
              <include>**/*.jar</include>
            </includes>
          </resource>
        </webResources>
      </configuration>
    </plugin>
  </plugins>
</build>

五、修改啟動(dòng)類

啟動(dòng)類繼承 SpringBootServletInitializer,并實(shí)現(xiàn) configure() 方法
原:

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class DemoApplication {

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

}

改后:

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;
import org.springframework.scheduling.annotation.EnableScheduling;

@SpringBootApplication
@EnableScheduling
public class DemoApplication extends SpringBootServletInitializer {

  @Override
  protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
    return application.sources(DemoApplication.class);
  }

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

}

六、修改配置文件

修改 application.yml 文件,標(biāo)明項(xiàng)目項(xiàng)目上下文路徑 context-path

server:
 servlet:
  context-path: /demo

七、修改靜態(tài)資源引入方式

我們使用 thymeleaf 模板引擎,引入 css、js 文件時(shí),需要加上項(xiàng)目上下文路徑
原:

<link rel="stylesheet" href="layui/css/layui.css" rel="external nofollow" media="all">

改后:

<link rel="stylesheet" th:href="@{/layui/css/layui.css}" rel="external nofollow" media="all">

我們需要使用 th:href="@{}" rel="external nofollow" 的方式,去引入靜態(tài)資源文件

八、測試

我們可以不使用項(xiàng)目的啟動(dòng)類啟動(dòng)項(xiàng)目,我們自己添加一個(gè)服務(wù)器來啟動(dòng)項(xiàng)目


就想普通的 SSM 項(xiàng)目,添加一個(gè) Tomcat 啟動(dòng)項(xiàng)目,如果能夠成功啟動(dòng)項(xiàng)目,并能正常訪問,那么打成 war 包也能夠正常運(yùn)行

到此這篇關(guān)于SpringBoot中打war包需要注意事項(xiàng)的文章就介紹到這了,更多相關(guān)SpringBoot打war包內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • java編程實(shí)現(xiàn)求解八枚銀幣代碼分享

    java編程實(shí)現(xiàn)求解八枚銀幣代碼分享

    這篇文章主要介紹了java編程實(shí)現(xiàn)求解八枚銀幣代碼分享,具有一定參考價(jià)值,需要的朋友可以了解下。
    2017-11-11
  • Java獲取文件ContentType案例

    Java獲取文件ContentType案例

    這篇文章主要介紹了Java獲取文件ContentType案例,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-08-08
  • idea2019導(dǎo)入maven項(xiàng)目中的某些問題及解決方法

    idea2019導(dǎo)入maven項(xiàng)目中的某些問題及解決方法

    這篇文章主要介紹了idea2019導(dǎo)入maven項(xiàng)目中的某些問題,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-08-08
  • Mybatis分頁查詢主從表的實(shí)現(xiàn)示例

    Mybatis分頁查詢主從表的實(shí)現(xiàn)示例

    本文主要介紹了Mybatis分頁查詢主從表的實(shí)現(xiàn)示例,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2024-09-09
  • 淺析Java中如何實(shí)現(xiàn)線程之間通信

    淺析Java中如何實(shí)現(xiàn)線程之間通信

    本篇文章主要介紹了淺析Java中如何實(shí)現(xiàn)線程之間通信。針對 Java 的線程間通信進(jìn)行了大致的講解,有興趣的可以了解一下
    2017-04-04
  • Java中的StackOverflowError錯(cuò)誤問題及解決方法

    Java中的StackOverflowError錯(cuò)誤問題及解決方法

    這篇文章主要介紹了Java中的StackOverflowError錯(cuò)誤,在本文中,我們仔細(xì)研究了StackOverflower錯(cuò)誤,包括Java代碼如何導(dǎo)致它,以及我們?nèi)绾卧\斷和修復(fù)它,需要的朋友可以參考下
    2022-07-07
  • SpringBoot集成RabbitMQ實(shí)現(xiàn)用戶注冊的示例代碼

    SpringBoot集成RabbitMQ實(shí)現(xiàn)用戶注冊的示例代碼

    這篇文章主要介紹了SpringBoot集成RabbitMQ實(shí)現(xiàn)用戶注冊的示例代碼,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-12-12
  • Java 關(guān)于String字符串原理上的問題

    Java 關(guān)于String字符串原理上的問題

    字符串廣泛應(yīng)用 在 Java 編程中,在 Java 中字符串屬于對象,Java 提供了 String 類來創(chuàng)建和操作字符串,讓我們一起來了解它
    2022-04-04
  • SpringBoot2.3新特性優(yōu)雅停機(jī)詳解

    SpringBoot2.3新特性優(yōu)雅停機(jī)詳解

    這篇文章主要介紹了SpringBoot2.3新特性優(yōu)雅停機(jī)詳解,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-05-05
  • Java concurrency集合之ConcurrentSkipListSet_動(dòng)力節(jié)點(diǎn)Java學(xué)院整理

    Java concurrency集合之ConcurrentSkipListSet_動(dòng)力節(jié)點(diǎn)Java學(xué)院整理

    這篇文章主要為大家詳細(xì)介紹了Java concurrency集合之ConcurrentSkipListSet的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-06-06

最新評論