javaspring-boothttpserver

What is a default port range for server.port=0 in spring boot application?


What is a default port range for server.port=0 in Spring Boot application?

I'm using spring-boot 2.7 (with default tomcat server) and working with java 11.

Or the range differs depending on OS?


Solution

  • The range for random ports depends on a couple of factors:

    If you are not running Spring Boot with root or administrator privilege, then the random port is likely to be between 1024 and 65535 (this is not a strict rule and can be different based on your OS configuration).

    However, Spring Boot doesn't set this range - the operating system's networking subsystem does. Spring Boot simply asks the OS to give it a available port, and the OS determines what port to hand out based on its own configuration.