午夜剧场伦理_日本一道高清_国产又黄又硬_91黄色网战_女同久久另类69精品国产_妹妹的朋友在线

您的位置:首頁技術文章
文章詳情頁

SpringBoot中打war包需要注意事項

瀏覽:46日期:2023-04-26 16:58:00

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

一、修改打包方式

原:

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

改后:

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

二、排除內置 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>

使用 排除內置服務器

三、添加 Tomcat 依賴

用于編譯和測試開發,兩種方式

1、

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

2、

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

四、改變項目的構造方式

原:

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

改后:

<build><!-- 一般為你的項目名,與配置文件中的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>

五、修改啟動類

啟動類繼承 SpringBootServletInitializer,并實現 configure() 方法原:

import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplicationpublic 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@EnableSchedulingpublic 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 文件,標明項目項目上下文路徑 context-path

server: servlet: context-path: /demo

七、修改靜態資源引入方式

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

<link rel='stylesheet' href='http://www.leifengta.com.cn/bcjs/layui/css/layui.css' rel='external nofollow' media='all'>

改后:

<link rel='stylesheet' th:href='http://www.leifengta.com.cn/bcjs/@{/layui/css/layui.css}' rel='external nofollow' media='all'>

我們需要使用 th:href='http://www.leifengta.com.cn/bcjs/@{}' rel='external nofollow' 的方式,去引入靜態資源文件

八、測試

我們可以不使用項目的啟動類啟動項目,我們自己添加一個服務器來啟動項目

SpringBoot中打war包需要注意事項

就想普通的 SSM 項目,添加一個 Tomcat 啟動項目,如果能夠成功啟動項目,并能正常訪問,那么打成 war 包也能夠正常運行

到此這篇關于SpringBoot中打war包需要注意事項的文章就介紹到這了,更多相關SpringBoot打war包內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!

標簽: Spring
相關文章:
主站蜘蛛池模板: 亚洲第一成人av | 欧洲精品在线观看 | 国产在线黄 | 91免费观看网站 | 久久综合五月天 | 五月天毛片 | 日本黄页在线观看 | 国产jjizz一区二区三区视频 | 久久久香蕉视频 | 久久视频在线观看 | 三级在线观看视频 | 婷婷丁香综合 | 伊人国产视频 | 中文字幕欧美视频 | 欧美日韩国产在线一区 | 国产成人三级在线观看视频 | 在线播放a| 日韩亚洲在线 | 91亚洲国产成人精品一区二区三 | 在线播放毛片 | 久久久久国 | 成人激情在线观看 | 国产精品高清在线观看 | 欧美成人aaa | 小毛片在线观看 | 在线精品国产 | 超碰com| 生活一级片| 日本超碰 | www.操操操 | 午夜在线免费视频 | 日韩综合在线观看 | 亚洲视频第一页 | 久久久成人免费视频 | 亚洲黄色激情 | 三级黄色片网站 | 天天视频黄色 | 深爱激情综合 | 久久人人爽人人爽人人片 | 国产一区二区三区高清 | 亚洲免费黄色 |