- 修改打包方式为war
<packaging>war</packaging>
- 移除springboot内置的tomcat
<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>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
- 修改启动类,继承SpringBootServletInitializer 并重写configure方法
@SpringBootApplication
@EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class})
public class QuickstartSpringBootsApplication extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(QuickstartSpringBootsApplication.class);
}
public static void main(String[] args) {
SpringApplication.run(QuickstartSpringBootsApplication.class, args);
}
}
- 打包后就可以部署到tomcat容器了,需要注意的是,部署后,访问的url需要带上war包名称