SpringBoot打war包,修改内置默认tomcat端口号

1.打war包,先把pom文件packaging由jar改成war:

    4.0.0
    com.example
    0.0.1-SNAPSHOT
    war
    Demo project for Spring Boot
    NB_Callbalk

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插件
添加代码

 
      
       org.springframework.boot 
       spring-boot-starter-tomcat
     


4.添加servlet-api的依赖

你可能感兴趣的:(spring)