Spring Boot项目发布到独立的Tomcat中运行
一:修改打包方式
<packaging>war</packaging>
二:由于SpringBoot默认嵌入了Tomcat,所以需要把它消除掉
<dependency>
<groupId>org.springframework.boot
<artifactId>spring-boot-starter-tomcat
<scope>provided
</dependency>
三:集成SpringBootServletInitializer,然后重写configure,将Spring Boot的启动类设置进去。
@SpringBootApplication
@ComponentScan (basePackages = “com.zz”)
public class App extends SpringBootServletInitializer {
protected SpringApplicationBuilder configure (SpringApplicationBuilder builder) { // 设置启动类,用于独立tomcat运行的入口
return builder.sources (App.class);
}
public static void main (String[] args) {
SpringApplication.run (App.class, args);
}
}