How does Spring Boot boot port start

  • 2020-05-24 05:33:11
  • OfStack

Spring Boot boot port

Spring Boot is integrated with the web container by default, and is started by the main function entry, just like normal Java program 1. Its built-in Tomcat container or Jetty container, depending on the configuration (the default is Tomcat). You can also package your project as an war package and put it in a separate web container (Tomcat, weblogic, etc.), but before that you need to make some simple adjustments to the application entry.

spring boot is a good thing, you can start directly in the main method without a container, and you don't need a configuration file to quickly set up the environment. However, when we want to start two springboot projects at the same time, there will be a problem. Port 8080 May be occupied by the first application, so that the second application cannot be started. At this time, the startup port of one project needs to be modified.

This can be achieved by implementing the EmbeddedServletContainerCustomizer interface:


public class Application extends SpringBootServletInitializer implements EmbeddedServletContainerCustomizer { 
 
  @Override 
  protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { 
    return builder.sources(Application.class); 
  } 
   
  public static void main(String[] args) { 
    SpringApplication.run(Application.class, args); 
  } 
 
 
  @Override 
  public void customize(ConfigurableEmbeddedServletContainer container) { 
    container.setPort(8081); 
  } 
} 

Thank you for reading, I hope to help you, thank you for your support of this site!


Related articles: