1.添加spring-boot-starter-tomcat的依賴,scope provided
2.添加maven-war-plugin插件
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
- 修改打包方式為war : <packaging>war</packaging>
3.spingboot Application類繼承SpringBootServletInitializer 并覆蓋configure方法
@SpringBootApplication
public class Demo extends SpringBootServletInitializer{
public static void main(String[] args) {
SpringApplication.run(Demo.class);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(Demo.class);
}
}