Spring Boot - Enable/Disable Actuator Endpoints

This tutorial shows you how to enable or disable actuator endpoints in Spring Boot, including how to set the endpoints to be exposed over HTTP and JMX.

Spring Boot has a feature called actuator which can be used to monitor and manage the application. It can be installed easily by adding spring-boot-starter-actuator as a dependency. There are several endpoints with each having a unique ID. By default, most of them are enabled. For an endpoint to be accessible, it must be exposed over HTTP, JMX, or both. In this tutorial, I am going to show you how to set which endpoints are enabled or disabled and how to set which endpoints are exposed over HTTP and JMX.

Enabling/Disabling Endpoints

All endpoints except shutdown are enabled by default. To enable or disable a specific endpoint, you can define an application property for it. The name of the property is management.endpoint.{id}.enabled. The id must be replaced with the ID of the endpoint. Below is the list of IDs as of version 3.1.3.

  • auditevents
  • beans
  • caches
  • conditions
  • configprops
  • env
  • flyway
  • health
  • httpexchanges
  • info
  • integrationgraph
  • loggers
  • liquibase
  • metrics
  • mappings
  • quartz
  • scheduledtasks
  • sessions
  • shutdown
  • startup
  • threaddump
  • heapdump*
  • logfile*
  • prometheus*

*: web application only (Spring MVC, Spring WebFlux, or Jersey)

You can see the latest list of endpoint IDs in the documentation.

The value of the property is either true or false. If it's set to true, it means the endpoint is enabled. Otherwise, the value is false, the endpoint is disabled.

Exposing Endpoints Over HTTP

By default, only the health endpoint that's exposed over HTTP. To change it, you can define a property named management.endpoints.web.exposure.include whose value is a comma-separated IDs. If you define that property, only the endpoints whose ID is defined in the property can be accessed over HTTP. To enable all endpoints over HTTP, you can write *. Here's an example for a .properties file that defines the list of endpoints exposed over HTTP.

  # only expose beans and info over HTTP
  management.endpoints.web.exposure.include=beans,info

  # expose all endpoints over HTTP
  management.endpoints.web.exposure.include=*

Here's another example for a .yaml file.

  # only expose beans and info over HTTP
  management:
    endpoints:
      web:
        exposure:
          include: beans,info

  # expose all endpoints over HTTP
  management:
    endpoints:
      web:
        exposure:
          include: "*"

There is also another property management.endpoints.web.exposure.exclude, which is used to exclude certain endpoints from being exposed over HTTP. Usually, it can be useful if you want to expose all endpoints except a few ones. Here's the example for a .properties file.

  # expose all endpoints except shutdown and info
  management.endpoints.web.exposure.include=*
  management.endpoints.web.exposure.exclude=shutdown,info

  # expose no endpoints
  management.endpoints.web.exposure.include=*
  management.endpoints.web.exposure.exclude=*

Here's another example for a .yaml file.

  # expose all endpoints except shutdown and info
  management:
    endpoints:
      web:
        exposure:
          include: "*"
          exclude: shutdown,info

  # expose no endpoints
  management:
    endpoints:
      web:
        exposure:
          include: "*"
          exclude: "*"

It's important to note that if an endpoint is disabled, it cannot be exposed.

Exposing Endpoints Over JMX

Just like HTTP, only the health endpoint is exposed over JMX by default. Spring also allows you to control which endpoints are exposed over JMX. The properties are very similar to those used for HTTP. Just replace web with jmx. For defining the list of endpoints to be exposed over JMX, the property you need to set is management.endpoints.jmx.exposure.include.

  # only expose beans and info over JMX
  management.endpoints.jmx.exposure.include=beans,info

  # expose all endpoints over JMX
  management.endpoints.jmx.exposure.include=*

Here's another example for a .yaml file.

  # only expose beans and info over JMX
  management:
    endpoints:
      jmx:
        exposure:
          include: beans,info

  # expose all endpoints over JMX
  management:
    endpoints:
      jmx:
        exposure:
          include: "*"

For adding the endpoints to be excluded, you have to set the value of management.endpoints.jmx.exposure.exclude property.

  # expose all endpoints except shutdown and info
  management:
    endpoints:
      jmx:
        exposure:
          include: "*"
          exclude: shutdown,info

  # expose no endpoints
  management:
    endpoints:
      jmx:
        exposure:
          include: "*"
          exclude: "*"

Summary

In Spring Boot, enabling or disabling an endpoint can be done by setting the values of application properties. You can set whether an endpoint is enabled or not. There are also properties to set the endpoints to be exposed over HTTP and JMX.