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 configurable from an environment variable, e.g. MICRONAUT_SERVER_PORT=8086

To run on a random port:

  1. micronaut:
  2. server:
  3. port: -1
Setting an explicit port may cause tests to fail if multiple servers start simultaneously on the same port. To prevent that, specify a random port in the test environment configuration.