Three ways to specify different ports in spring boot

Three ways to specify different ports in spring boot

1) Create the file application.properties under src/main/resources in the configuration file, the
port is:
server.port=9090


2) The embedded startup server
  can implement the EmbeddedServletContainerCustomizer interface To implement:
import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer;
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;

public class CustomContainer implements EmbeddedServletContainerCustomizer {
    @Override
    public void customize(ConfigurableEmbeddedServletContainer container) {
        container.setPort(9090 );
    }
}

3) When the command line starts the JAR:
   java -Dserver.port=9090 -jar executable.jar
or:
java -jar executable.jar –server.port=9090

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326114125&siteId=291194637