If you want to change the application context path (application root) and server port for any spring boot application, you can utilize any of below two methods:
1. application.properties file
Use server.port
and server.contextPath
properties.
#server port server.port=9000 #application root server.contextPath=/springexamples
2. Customize WebServerFactoryCustomizer
Implement WebServerFactoryCustomizer
interface and override customize()
method.
import org.springframework.boot.web.server.WebServerFactoryCustomizer; import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory; import org.springframework.stereotype.Component; @Component public class CustomizationBean implements WebServerFactoryCustomizer<ConfigurableServletWebServerFactory> { @Override public void customize(ConfigurableServletWebServerFactory server) { server.setPort(9000); server.setContextPath("/springexamples"); } }
Ask Questions & Share Feedback