在配置文件中设置打包方式为war
<packaging>war</packaging>
修改启动类,继承SpringBootServletInitializer类,并且重写configure方法
public class XdclassApplication extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(XdclassApplication.class);
}
public static void main(String[] args) throws Exception {
SpringApplication.run(XdclassApplication.class, args);
}
}
确保内置servlet container 不会干涉发布该war包的servlet container,方案是标记内置servlet container 的依赖为 provided,打好war 包 放在 tomcat下就可以了
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>