Spring Boot打war包的實例教程
Spring Boot除了可以打可執(zhí)行jar包外,也支持傳統(tǒng)的war包。本文介紹如何使用Spring Boot構(gòu)建傳統(tǒng)war包。
Spring Boot打war包步驟如下:
1、在pom.xml里定義打包類型
<packaging>war</packaging>
2、添加Spring Boot啟動器(也可通過parent)
<dependencyManagement> <dependencies> <dependency> <!-- Import dependency management from Spring Boot --> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-dependencies</artifactId> <version>1.5.6.RELEASE</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement>
3、添加spring-boot-starter-web依賴
<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>
4、添加打包插件
<build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build>
5、主類繼承SpringBootServletInitializer
/**
* WAR application
*/
@SpringBootApplication
public class WarApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(WarApplication.class, args);
}
}
6、執(zhí)行mvn clean package打包
$mvn clean package
7、將打好的war包拷貝到容器(如tomcat)運行即可。
這里需要簡單說明下:
主應(yīng)用可以重寫SpringBootServletInitializer里面有configure方法,自定義配置Spring Boot。
/**
* Configure the application. Normally all you would need to do is to add sources
* (e.g. config classes) because other settings have sensible defaults. You might
* choose (for instance) to add default command line arguments, or set an active
* Spring profile.
* @param builder a builder for the application context
* @return the application builder
* @see SpringApplicationBuilder
*/
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder;
}
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Java使用Soap方式調(diào)用WebService接口代碼示例
Java調(diào)用WebService接口是指通過Java語言來訪問并與WebService進行交互,WebService是一種基于Web的服務(wù)架構(gòu),它通過標準的XML和HTTP協(xié)議來提供服務(wù),這篇文章主要給大家介紹了關(guān)于Java使用Soap方式調(diào)用WebService接口的相關(guān)資料,需要的朋友可以參考下2024-03-03
使用springboot+druid雙數(shù)據(jù)源動態(tài)配置操作
這篇文章主要介紹了使用springboot+druid雙數(shù)據(jù)源動態(tài)配置的操作,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2021-09-09
Spring?Cloud?整合?nacos實現(xiàn)動態(tài)配置中心的詳細步驟
這篇文章主要介紹了Spring?Cloud?整合?nacos?實現(xiàn)動態(tài)配置中心,整合步驟是通過添加依賴新建nacos配置,本文分步驟通過實例代碼給大家詳細講解,需要的朋友可以參考下2022-10-10

