詳解Spring Boot 部署jar和war的區(qū)別
本文介紹了Spring Boot 部署jar和war兩種方式的區(qū)別,分享給大家,具體如下:
1、 packaging的方式不同,一種設(shè)置成jar一種是war
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>cn.vcyber.www</groupId> <artifactId>vcyber-api</artifactId> <!--這個地方有所區(qū)別 --> <packaging>war</packaging> <version>1.0-SNAPSHOT</version> <name>vcyber-api</name> <url>http://maven.apache.org</url>
2、 繼承的方式不同
Application.java需要繼承SpringBootServletInitializer,而jar包不需要。
下面是war繼承的方式:
@SpringBootApplication
@RestController
public class Application extends SpringBootServletInitializer{
public static void main(String[] args) {
SpringApplication.run(Application.class,args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(Application.class);
}
}
3、spring boot內(nèi)置tomcat
springboot內(nèi)置tomcat容器,默認(rèn)tomcat8的版本,war包部署時,需要在pom文件中有關(guān)跟tomcat有關(guān)系的jar包scope都設(shè)置成provided。
去掉spring boot內(nèi)置的tomcat代碼:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<artifactId>log4j-over-slf4j</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
SpringBoot+Kotlin中使用GRPC實現(xiàn)服務(wù)通信的示例代碼
本文主要介紹了SpringBoot+Kotlin中使用GRPC實現(xiàn)服務(wù)通信的示例代碼,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-07-07

