1. Modify the packaging form
Set in pom.xm:
<packaging>war</packaging>
Second, remove the embedded tomcat package
Set in pom.xml:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <!-- remove embedded tomcat plugin--> <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> </exclusion> </exclusions> </dependency>
3. Add servlet-api dependency
<dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>3.1.0</version> <scope>provided</scope> </dependency>
or
<dependency> <groupId>org.apache.tomcat</groupId> <artifactId>tomcat-servlet-api</artifactId> <version>8.0.36</version> <scope>provided</scope> </dependency>
Fourth, modify the startup class and rewrite the initialization method
In the same level directory of the startup class, add a class: SpringBootStartApplication
/** * Modify the startup class, inherit SpringBootServletInitializer and override the configure method */ public class SpringBootStartApplication extends SpringBootServletInitializer { @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { // Note that this should point to the Application startup class that was originally executed with the main method return builder.sources(Application.class); } }
In this way, after completing the above modifications, it can be packaged and deployed in tomcat.
http://blog.csdn.net/yalishadaa/article/details/70037846