【1】启动类上配置@ServletComponentScan注解,以及继承SpringBootServletInitializer类
@SpringBootApplication
@ServletComponentScan
public class UserOrderStarter extends SpringBootServletInitializer{
public static void main(String[] args) {
SpringApplication.run(UserOrderStarter.class, args);
}
}
@ServletComponentScan表示使用@WebServlet、@WebFilter、@WebListener标记的 Servlet、Filter、Listener 就可以自动注册到Servlet容器中。
【2】pom文件中,设置打包方式为war包方式
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
【3】pom文件中,添加以下依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
表示让springboot内置服务器在不参与打包的过程