I have a Java Spring Boot Application, which is currently running on http://localhost:8080. I will be containerising this application to be deployed in Kubernetes. For this I have enabled the actuator health
endpoint by adding the following to the pom.xml
file.
<!-- Spring boot actuator to expose metrics endpoint -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
Now, the application Health Endpoint works successfully on http://localhost:8080/actuator/health endpoint. I wish to change the PORT of the Health Endpoint URL to be 8081. (This is to ensure that I can expose 8080 port to the public and expose 8081 port only to the load balancer. This is a personal preference)
How can I change the port of the Health Endpoint so that the health endpoint URL becomes http://localhost:8081/actuator/health, and the application runs on http://localhost:8080/.
To make the application listen on a different port, set the external property: management. server. port . To listen on a completely different network address (such as when you have an internal network for management and an external one for user applications), you can also set management.
address is the property used to specify the list of addresses from where we want to listen. If we want to listen to management requests only from the localhost, then specify the property value as 127.0. 0.1. For this to work, the management endpoint must be configured to a different port from the HTTP port.
All examples below are for Spring Boot 2.x. The default actuator health endpoint would be http://localhost:8080/actuator/health. Option 1: Change /actuator/health to be a Custom Path like /actuator/test Add the following to your application.properties file Option 2: Change /actuator/health to be a Custom Path like /myapp/test
The actuator provides production-ready features for Spring Boot application .It will help us to check and manage our application in the production environment.There are a number of endpoints provided by Spring Boot however we may want to create a custom endpoint using Spring Boot Actuator.
We can change the port of the Spring Boot in the following ways: By Adding the configuration in the application properties of the Spring Boot project By Implementing the WebServerFactoryCustomizer interface in the component class First, we need to establish the spring application in our project.
Spring boot makes health checks easier for us by providing opinionated /actuator/health endpoint. The HealthEndpoint of spring-boot-starter-actuator module collects Health information for any beans that are defined as HealthIndicator. For a simple web application, there are two HealthIndicator beans Auto-Configured by default.
As pointed out by GreenGiant, the Spring Boot 5+ way of doing this is through:
management.server.port
By default, actuator will be accessible using the default http port configured (commonly 8080).
Actuator has a number of configuration properties you can configure that fall under the management.
prefix. You can specifically set the management.port
in application.properties
to have actuator endpoints to be served on the custom port:
In application.properties
, set:
management.port=8081
For more details, check section 48.2 of the Spring Boot - Production Ready Monitoring documentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With