How to configure port for a Spring Boot application

ghz 1years ago ⋅ 8217 views

Question

How do I configure the TCP/IP port listened on by a Spring Boot application, so it does not use the default port of 8080.


Answer

As [said in docs](http://docs.spring.io/spring- boot/docs/current/reference/htmlsingle/#howto-change-the-http-port) either set server.port as system property using command line option to jvm -Dserver.port=8090 or add application.properties in /src/main/resources/ with

server.port=8090

For a random port use:

server.port=0

Similarly add application.yml in /src/main/resources/ with:

server:
  port: 8090