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.
As explained in Spring documentation, there are several ways to do that:
Either you set the port in the command line (for example 8888)
-Dserver.port=8888
or --server.port=8888
Example : java -jar -Dserver.port=8888 test.jar
Or you set the port in the application.properties
server.port=${port:4588}
or (in application.yml with yaml syntax)
server:
port: ${port:4588}
If the port passed by -Dport (or -Dserver.port) is set in command line then this port will be taken into account. If not, then the port will be 4588 by default.
If you want to enforce the port in properties file whatever the environment variable, you just have to write:
server.port=8888