Change Tomcat Port in a Spring Boot application
By default Spring Boot uses Tomcat as the container and runs the server on 8080 port. However you can change the Tomcat port in following ways:
1) Change port by specifying the port in application.properties or application.yml file using server.port property.
application.properties file
server.port=8090
application.yml file
server: port : 8090
2) Change port using command line argument
java -Dserver.port=8090 -jar yourapplication.jar
3) Change port by implementing EmbeddedServletContainerCustomizer interface
package com.example.demo; import org.springframework.boot.web.server.WebServerFactoryCustomizer; import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory; import org.springframework.stereotype.Component; @Component public class WebServerFactoryCustomizerImpl implements WebServerFactoryCustomizer<ConfigurableServletWebServerFactory> { @Override public void customize(ConfigurableServletWebServerFactory server) { server.setPort(8090); // change tomcat port } }
References :
Spring Boot Docs how to change the http port