Spring Boot 2 Actuator Endpoint

Here we will talk about the Spring Boot 2 Actuator Endpoints. I will cover below points in this article. At any point you can refer GITHUB repository for Spring Boot 2 Actuator.

Read more: Spring Boot 2 Actuator Endpoint
  • Configuration
  • URL / path
  • Enable & Expose

Enable & Expose

Before we work with endpoint, we need to understand the difference between Exposed and Enabled Endpoint.

In order to access a specific Endpoint, it needs to be enabled and exposed both. If an endpoint is disabled, it will be removed from application context entirely.

shutdown is the only endpoint which is disabled by default. Though endpoints are enabled, only below two endpoints are exposed by default.

  • health
  • info

It means, if you want to access any other endpoint, you have to configure that as per your needs.

Enable Endpoint

Though all endpoint except shutdown is enabled by default. But there might be scenario when you want to disable specific endpoint or enable shutdown endpoint. Below configurations can be used to enable / disable specific endpoint.

management:
  endpoint:
    shutdown:
      enabled: true # Disabled By Default
    info:
      enabled: true # Enabled by Default
    beans:
      enabled: false

Expose Endpoint

Developer needs to write the explicit configuration code to expose other endpoints. Include / exclude parameter can be used to configure the endpoints as per the requirement.

management:
 endpoints:
   web:
     exposure:
       include: '*' # Enable all endpoint over HTTP
       exclude: env # Do not expose env endpoint

Actuator Endpoint Configuration

Only thing you need to do to enable Spring Boot Actuator Endpoint is to add below dependency.

For maven project

<dependency>
   <artifactId>spring-boot-starter-actuator</artifactId>
   <groupId>org.springframework.boot</groupId>
</dependency>

For gradle project

dependencies { implementation 'org.springframework.boot:spring-boot-starter-actuator' }

Default Endpoints (INFO, HEALTH) will be exposed and enabled just by adding above dependency.

Below is the list of important Endpoints.

infoDisplays Information about Application. Details added in INFO endpoint can be customized.
healthDisplays application health status.
envDisplays a list of environment properties
logfileDisplays the content of logfile
beansDisplays the complete list of all the spring beans
loggersDisplays and modifies the logger level.
shutdownA way to shut down the application gracefully. (Disabled by default). Be careful while enabling it.

info and health endpoints can be customised easily to suit our needs. We will explain each of these endpoint in details in there respective articles.

Base path

Spring Boot configures all enabled endpoints to be exposed over HTTP. By default, the base path will be /actuator.
ID(eg. info/health) of the specific endpoint can be used along with base path (/actuator) to find the final URL path.

Info Endpoint: /actuator/info
Health Endpoint: /actuator/info

Default base path (management endpoint) can be configured as per your needs. Though it is not required, but as developer you might have your own preferences. So to change the base path you can add below configuration in YML file.

endpoints:
 web:
   exposure:<em>
 </em>    base-path: /mgmt

After adding above configuration, base path will be /mgmt and URL for different endpoint will be like below.

Info Endpoint: /mgmt/info
Health Endpoint: /mgmt/info

Endpoint List

Now, You have configured the endpoints base path. You know how to access individual endpoints. But, what if you want to access all the endpoint which are exposed by the Spring Boot application. You can view all the endpoints exposed by the application by going to the base path URL.

<em>http://localhost:9092/mgmt/</em>

Disable security

If your application has spring security configured. Chances are all the actuator links protected. To disable the security for endpoints you can use below configuration code.

http.authorizeRequests()
.requestMatchers(EndpointRequest.<em>toAnyEndpoint</em>())
.permitAll();

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.