最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

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

最近在做一個(gè)項(xiàng)目,遇到了項(xiàng)目打成 war 包的一個(gè)問(wèn)題,項(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 依賴(lài)

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

1、

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

2、

<dependency>
  <groupId>org.apache.tomcat</groupId>
  <artifactId>tomcat-servlet-api</artifactId>
  <version>8.5.34</version>
  <!-- 該包只在編譯和測(cè)試的時(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)類(lèi)

啟動(dòng)類(lèi)繼承 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)資源文件

八、測(cè)試

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


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

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

相關(guān)文章

  • springboot的jar包如何啟用外部配置文件

    springboot的jar包如何啟用外部配置文件

    本文主要介紹了springboot的jar包如何啟用外部配置文件,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2023-06-06
  • java接口性能優(yōu)化技巧

    java接口性能優(yōu)化技巧

    這篇文章主要為大家介紹了java接口性能優(yōu)化技巧示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-07-07
  • 關(guān)于spring依賴(lài)注入的方式以及優(yōu)缺點(diǎn)

    關(guān)于spring依賴(lài)注入的方式以及優(yōu)缺點(diǎn)

    這篇文章主要介紹了關(guān)于spring依賴(lài)注入的方式以及優(yōu)缺點(diǎn),依賴(lài)注入,是IOC的一個(gè)方面,是個(gè)通常的概念,它有多種解釋,這概念是說(shuō)你不用創(chuàng)建對(duì)象,而只需要描述它如何被創(chuàng)建,需要的朋友可以參考下
    2023-07-07
  • Intellij IDEA安裝lombok插件及使用詳解

    Intellij IDEA安裝lombok插件及使用詳解

    今天小編就為大家分享一篇關(guān)于Intellij IDEA安裝lombok插件及使用詳解,小編覺(jué)得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來(lái)看看吧
    2018-12-12
  • Java Web最近面試題匯總

    Java Web最近面試題匯總

    在本篇文章里小編給大家整理的是一篇關(guān)于Java Web最近面試題匯總內(nèi)容,需要的朋友們可以學(xué)習(xí)下。
    2020-02-02
  • Java中常見(jiàn)的日期操作(取值、轉(zhuǎn)換、加減、比較)

    Java中常見(jiàn)的日期操作(取值、轉(zhuǎn)換、加減、比較)

    本文給大家介紹java中常見(jiàn)的日期操作,日期取值、日期轉(zhuǎn)換、日期加減、日期比較,對(duì)java日期操作相關(guān)知識(shí)感興趣的朋友一起學(xué)習(xí)吧
    2015-12-12
  • SpringCloud實(shí)戰(zhàn)之Zuul網(wǎng)關(guān)服務(wù)

    SpringCloud實(shí)戰(zhàn)之Zuul網(wǎng)關(guān)服務(wù)

    服務(wù)網(wǎng)關(guān)是分布式架構(gòu)中不可缺少的組成部分,是外部網(wǎng)絡(luò)和內(nèi)部服務(wù)之間的屏障。這篇文章主要介紹了SpringCloud實(shí)戰(zhàn)之Zuul網(wǎng)關(guān)服務(wù)。一起跟隨小編過(guò)來(lái)看看吧
    2018-05-05
  • 解決異常處理問(wèn)題:getReader()?has?already?been?called?for?this

    解決異常處理問(wèn)題:getReader()?has?already?been?called?for?this

    這篇文章主要介紹了解決異常處理:getReader()?has?already?been?called?for?this問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-01-01
  • Java中判斷集合是否相等的幾種方法詳解

    Java中判斷集合是否相等的幾種方法詳解

    這篇文章主要介紹了Java中判斷集合是否相等的幾種方法詳解,在平時(shí)的開(kāi)發(fā)中,可能會(huì)遇到需要判斷兩個(gè)集合是否相等的需求,那么本文就來(lái)詳細(xì)講解一下幾種實(shí)現(xiàn)方法,需要的朋友可以參考下
    2023-08-08
  • Spring 中使用反射創(chuàng)建 Bean 實(shí)例的幾種方式

    Spring 中使用反射創(chuàng)建 Bean 實(shí)例的幾種方式

    文章介紹了在Spring框架中如何使用反射來(lái)創(chuàng)建Bean實(shí)例,包括使用Class.newInstance()、Constructor.newInstance()、工廠方法以及Spring的BeanUtils工具類(lèi),文章還強(qiáng)調(diào)了反射操作的注意事項(xiàng),如異常處理、性能、安全性以及類(lèi)型安全,感興趣的朋友一起看看吧
    2025-03-03

最新評(píng)論

西峡县| 汉寿县| 平利县| 加查县| 兖州市| 岐山县| 宁安市| 威信县| 中卫市| 响水县| 崇仁县| 江油市| 山阳县| 桂林市| 县级市| 清流县| 濮阳市| 周口市| 辽中县| 庆安县| 高邮市| 兴国县| 衡东县| 蓬安县| 防城港市| 白银市| 比如县| 图木舒克市| 连城县| 上虞市| SHOW| 宜良县| 新绛县| 台南县| 开阳县| 佛冈县| 尤溪县| 定兴县| 惠州市| 兴安盟| 吴川市|