by BehindJava

How to configure port for a Spring Boot application

Home » springboot » How to configure port for a Spring Boot application

In this tutorial we are going to learn about configuring the port number for a Spring Boot application.

when we generate a Spring Boot project using Spring Initializr or Spring tool suite IDE a file named is also generated by default with the project under src/main/resources directory.

As said set server.port as system property using command line option to jvm -Dserver.port=8090 or add in /src/main/resources/ with


For random port use


Similarly we can also add application.yml in /src/main/resources/ with

  port : 8090

Imagine a scenario where you have , application.yml files under /src/main/resources/ and youre also passing the port no as a command line argument to a spring boot application that you want to run.

In the above scenario which port no is considered by the spring boot application?

Firstly the port no passed as a command line argument is given high priority since this is happening at the runtime and then follewed by and application.yml.