springboot has a built-in Tomcat server, which can directly package the project into a jar to run, but sometimes we need to package the project as a war file and deploy it in the web server. The following are the steps to deploy the springboot project as a war project:
1. Modify the packaging tag value in pom.xml to war
2. Create a new subclass that inherits from SpringBootServletInitializer (similar to Spring Boot's startup class), the code is as follows:
package com.aci; 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 org.springframework.cache.annotation.EnableCaching; import org.springframework.scheduling.annotation.EnableScheduling; @SpringBootApplication @EnableScheduling @EnableCaching public class WebApplication extends SpringBootServletInitializer{ public static void main(String[] args) { SpringApplication.run(WebApplication.class, args); } @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { return application.sources(WebApplication.class); } }
3. Modify the value of the start-class child node of the properties node of the pom.xml file to the value of the class created above. The code is as follows:
<properties> <start-class>com.aci.WebApplication</start-class> <java.version>1.8</java.version> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <springboot.version>1.5.9.RELEASE</springboot.version> <poi.version>3.15</poi.version> </properties>