Showing posts with label configure port. Show all posts
Showing posts with label configure port. Show all posts

Tuesday, 27 August 2019

Run Spring boot application on random port


If you set the property 'server.port' to 0, then the application runs on random free port.
@SpringBootApplication
public class App {
	public static void main(String[] args) {
		System.setProperty("server.port","0");
		SpringApplication.run(App.class, args);
	}	
}


Once you ran App.java, you can see the port details in console messages.
2019-07-18 13:40:14.311  INFO 38037 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 52709 (http) with context path ''

In my case, application started running on port 52709.

If you would like to know different ways to customize the post, I would recommend you to go through the post ‘How to configure port for a spring boot application?’.


You can download the complete working application from this link.



Previous                                                    Next                                                    Home