1.打war包,先把pom文件packaging由jar改成war:
2.Application文件:
@SpringBootApplication
public class Application extends SpringBootServletInitializer
implements EmbeddedServletContainerCustomizer {
public static void main(String[] args) {
ConfigurableApplicationContext run = SpringApplication.run(Application.class, args);
}
//集成SpringBootServletInitializer,configure实现打war包
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(Application.class);
}
//下边customize方法实现EmbeddedServletContainerCustomizer 接口,实现了
//更改tomcat端口号的需求
@Override
public void customize(ConfigurableEmbeddedServletContainer container) {
container.setPort(8080);
}
}
3.pom文件的spring-boot-starter-web里添加代码,移除嵌入式tomcat插件
添加代码,这段就老生常谈了
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
4.添加servlet-api的依赖
题外
改变war包包名
pom文件build关键字里加上
包名