What's the difference between management.server.port and management.port properties?

Diamond picture Diamond · Jul 15, 2018 · Viewed 7.4k times · Source

To run Actuator on a separate port we write management.server.port: 9001 in the application.properties file. But there is a confusing line in Actuator Guide code:

@TestPropertySource(properties = {"management.port=0"})

And then ...

@Value("${local.management.port}")
private int mgt;

Here is the source class https://github.com/spring-guides/gs-actuator-service/blob/master/complete/src/test/java/hello/HelloWorldApplicationTests.java

What's the difference between management.server.port, management.port and local.management.port?

Answer

Sri9911 picture Sri9911 · Jul 19, 2018

The management.server.port is used to expose management/actuator endpoints to a different HTTP port other than the one used for running the application.

And the management.port=0 is used to provide random port for the actuator to run while integration testing.

Whereas local.management.port is used to inject the random port.

Reference Spring Boot Actuator: Production-ready features and Random Port for Actuator