Sub topic 2
Enabling and exposing endpoints over HTTP and JMX
This chapter assumes you have a working Spring Boot application, know how to edit application.yml, and have read the previous chapter, which added the Actuator starter to the build. Here you will learn the difference between an endpoint being enabled and being exposed, and how to control exposure over HTTP and JMX.
Enabled versus exposed
Every Actuator endpoint has two separate settings:
- Enabled means the endpoint bean exists in the application context. Most endpoints are enabled by default. The
shutdownendpoint is the exception. - Exposed means the endpoint is reachable through a technology, such as HTTP or JMX.
An endpoint must be both enabled and exposed to be reachable. This split is the most common source of confusion. If /actuator/metrics returns 404, the endpoint is usually enabled but not exposed.
The defaults for exposure differ by technology:
| Technology | Exposed by default |
|---|---|
| HTTP | `health` only |
| JMX | all enabled endpoints |
HTTP exposure is limited because endpoints such as env and heapdump can leak secrets and internal details.
Choosing what to expose over HTTP
Use include and exclude under management.endpoints.web.exposure:
management:
endpoints:
web:
exposure:
include: health,info,metrics,prometheus,loggersStart the application and request the discovery page:
curl http://localhost:8080/actuatorThe response lists a link for every exposed endpoint. Only the five endpoints in include appear, plus the self link.
You can use * to expose everything. In YAML, quote it, because a bare * is parsed as an alias marker:
management:
endpoints:
web:
exposure:
include: "*"
exclude: env,heapdumpexclude wins over include, so this exposes everything except env and heapdump.
Enabling and disabling individual endpoints
Use management.endpoint.<id>.enabled to switch a single endpoint on or off. The key is endpoint (singular) here, not endpoints:
management:
endpoint:
shutdown:
enabled: true
env:
enabled: falseDisabling an endpoint removes it entirely, even from JMX. To turn off every endpoint by default and opt in one at a time, set management.endpoints.enabled-by-default to false. Then enable only the ones you need.
Exposing endpoints over JMX
JMX (Java Management Extensions) is the standard Java mechanism for managing a running JVM. Tools such as JConsole and VisualVM can read Actuator endpoints as MBeans when they are exposed this way. The settings mirror the web ones:
management:
endpoints:
jmx:
exposure:
include: health,metricsOpen JConsole, connect to your application's process, and look under the org.springframework.boot domain in the MBeans tab.
Spring Boot 3 changed the JMX default. JMX support is only active when you set spring.jmx.enabled=true, so add that property if no MBeans appear.
Common errors
- 404 on an endpoint that exists. It is enabled but not exposed. Add its id to
include. - YAML parse error on
include: *. Quote the asterisk. - Typing
management.endpoints.shutdown.enabled. The correct prefix ismanagement.endpoint.shutdown.enabled. - Config seems ignored. Check that the property is in the active profile and that an
excludeentry is not overriding yourinclude.
Exercise
Your application has management.endpoints.web.exposure.include=health,metrics, but a request to /actuator/shutdown returns 404 even after you set management.endpoint.shutdown.enabled=true. What is missing?
Show answer
The shutdown endpoint is now enabled, but it is not exposed over HTTP. Add shutdown to the management.endpoints.web.exposure.include list. Both enabling and exposure are required.
Exercise
You want to expose every endpoint over HTTP except heapdump. Which two properties do you set, and what must you remember in YAML?
Show answer
Set management.endpoints.web.exposure.include to "*" and management.endpoints.web.exposure.exclude to heapdump. Quote the asterisk in YAML.