How to configure port for a Spring Boot application?

0 votes
414 views
asked Nov 23, 2020 by Hitesh Garg (799 points)  

I want to run multiple Spring boot applications on local and as soon second application I start getting Port already in use error.
How can I configure the port of application in Spring boot?

1 Answer

0 votes
answered Dec 5, 2020 by Hitesh Garg (799 points)  
 
Best answer

By default the port used for an application is 8080. We can configure the port by adding the details in the /src/main/resources/application.properties file.

As per the docs either set server.port as system property using command line option to jvm -Dserver.port=8090 or

In application.properties add

server.port=8090

OR for a Random port

server.port=0 //For random port use

If you are using application.yml then add

server:
  port : 8090
...