There is a pitfall: The official website document points out the following first 3 steps, but this way you can only make a runnable jar package. To type the war package, you have to jump to another page at the link behind the document to find the fourth step, that is, you can finally type the war package. Some friends may be careless and fail to find the link to the fourth step, but they think that they can type the war package after only doing the first three steps. As a result, they keep making mistakes, and they think there is something wrong with their business code, and then they keep making trouble, wasting a lot of time (such as me), so I wrote the whole process here.
1.Specify the war packaging method
<packaging>jar</packaging>
2.pom.xml add spring-boot-maven-plugin plugin
<build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <version>2.0.1.RELEASE</version> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> </plugin> </plugin> </plugins></build>
3.pom.xml add spring-boot-starter-tomcat dependency
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <scope>provided</scope></dependency>
4. The startup class inherits SpringBootServletInitializer and overrides the configure method
@SpringBootApplicationpublic class Application extends SpringBootServletInitializer { @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { return application.sources(Application.class); } public static void main(String[] args) throws Exception { SpringApplication.run(Application.class, args); }}Summarize
The above is the method of Spring Boot+maven to make war packages introduced to you by the editor. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support to Wulin.com website!