1、修改pom.xml
父工程的pom.xml中的 <packaging>pom</packaging>
spring boot项目应用中pom.xml中的 <packaging>war<packaging>
<!--在父工程的pom.xml里,去除springboot web自带的tomcat,自己添加tomcat、servlet-api 依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
2.在有启动类的项目中,让启动类继承 SpringBootServletInitializer
,重写 configure
方法。
@SpringBootApplication
public class DemoApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(DemoApplication .class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
// 注意这里要指向原先用main方法执行的Application启动类
return builder.sources(DemoApplication .class);
}
}
想要实时关注更多干货好文,扫描下图关注:
其他与之相关的异常请前往Springboot、Springcloud、Eureka
写在最后: