6.2 Running Server on a Specific Port

By default the server runs on port 8080. However, you can set the server to run on a specific port:

  1. micronaut:
  2. server:
  3. port: 8086
This is also possible to be configured from an environment variable: MICRONAUT_SERVER_PORT=8086

To run on a random port:

  1. micronaut:
  2. server:
  3. port: -1
If an explicit port is set, that may cause tests to fail because multiple servers are starting simultaneously on the same port. To prevent that, set the port to be random in the test environment configuration.