修改Spring boot的啓動類,繼承SpringBootServletInitializer類。html
package cn.com.cmbx; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.web.support.SpringBootServletInitializer; import javax.swing.*; @SpringBootApplication public class Application extends SpringBootServletInitializer { @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { return builder.sources(Application.class); } public static void main(String[] args) { SpringApplication.run(Application.class, args); } }
修改打包方式,將java
<packaging>jar</packaging>
修改成web
<packaging>war</packaging>
<!-- 如需打成war包 確保嵌入的servlet容器不會干擾部署war文件的servlet容器 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <scope>provided</scope> </dependency>
<build> <!-- 設置打包名稱 --> <finalName>zh</finalName> <plugins> <!-- 構建工具 --> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> <plugins> <build>
以idea中maven項目爲例,右側窗口調出maven,先clean,再package,控制檯提示 Build Success便可在相應路徑下得到war包。spring
參考資料:http://www.javashuo.com/article/p-mzrbmhop-v.html 參考資料:https://docs.spring.io/spring-boot/docs/2.1.0.RELEASE/reference/htmlsingle/#howto-create-a-deployable-war-filetomcat