spring-boot auto change port if port is already used

Viewed 711

I am using Windows command to run my spring-boot application with emblemed tomcat. Beside, I need to run many console application using CommandlineRunner. Off cource I am facing port in use issue.

***************************
APPLICATION FAILED TO START
***************************
Description:
Web server failed to start. Port 8080 was already in use.
Action:
Identify and stop the process that's listening on port 8080 or configure this application to listen on another port.

I can set port in every console application but I need to run at least 10 console application at the same time.

Do I have any config or solution for application auto-change port?

1 Answers

You can auto generate port number to get rid from Port was already in use. just put server.port= 0 in properties or yml. It is auto generate server port in console.

application.properties

server.port= 0

application.yml

server:
  port : 0

console

enter image description here

Related