1、<packaging>war</packaging>
2、消除内置tomcat,二选一。
(1) <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>
(2)<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
<!--消除内置的tomcat-->
</dependency>
3、修改main类中的方法,方法二选一(意义上是一样的,只不过一个是添加一个类,另一个是在main类中添加一个方法)。
(1)、启动类继承SpringBootServletInitializer实现APP:
public class Application extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Override
protected SpringApplicationBuilder APP(SpringApplicationBuilder builder) {
return builder.sources(Application.class);
}
}
4、把打好的war包挡在webapps里边,windows下运行startup.bat,linux下运行startup.sh。
(2)、新添加一个类继承SpringBootServletInitializer。
public class ServletInitializer extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
//此处的Application.class为带有@SpringBootApplication注解的启动类
return builder.sources(Application.class);
}
}