Sub topic 2
Enabling and Exposing Endpoints over HTTP and JMX
This chapter assumes you can build a Spring Boot application with Maven or Gradle, edit application.yml, and read basic HTTP and JSON. You have already added the Actuator starter in the previous chapter. Here you learn how Actuator decides which endpoints exist and which of them a client can reach.
Two separate settings: enabled and exposed
Every Actuator endpoint has two independent states.
- Enabled means the endpoint bean is created in the application context. A disabled endpoint does not exist at all.
- Exposed means the endpoint is reachable through a technology, such as HTTP or JMX.
An endpoint must be both enabled and exposed to be usable. Most mistakes in this area come from mixing up the two. If /actuator/metrics returns 404, the endpoint is usually not exposed over HTTP. Turning on more switches will not help if it is not enabled in the first place.
In Spring Boot 3.x, the behavior is as follows. These are the defaults.
- All endpoints except
shutdownare enabled. - Over HTTP, only
healthis exposed. - Over JMX, all enabled endpoints are exposed.
The HTTP default is deliberately conservative. Endpoints such as env and heapdump can reveal secrets or internal structure, so Boot makes you opt in.
Listing the available endpoints
Some of the endpoints you meet most often are listed below.
| Endpoint ID | What it shows |
|---|---|
| `health` | Application health status |
| `info` | Application, build, and git information |
| `metrics` | Micrometer metric names and values |
| `prometheus` | Metrics in Prometheus text format |
| `loggers` | Logger levels, which can be changed at runtime |
| `env` | Environment properties |
| `beans` | All beans in the context |
| `mappings` | Request mappings |
| `threaddump` | A snapshot of all threads |
| `shutdown` | Stops the application (disabled by default) |
The prometheus endpoint exists only when the Micrometer Prometheus registry is on the classpath. Later chapters cover most of these in detail.
With a default setup, start the application and request the discovery page.
curl -s http://localhost:8080/actuatorThe response is a JSON document with a _links object. It lists only endpoints that are both enabled and exposed, so it is a quick way to check your configuration. With the defaults, you see self, health, and health-path.
Exposing endpoints over HTTP
The properties management.endpoints.web.exposure.include and management.endpoints.web.exposure.exclude control HTTP exposure. Both take a comma-separated list of endpoint IDs.
management:
endpoints:
web:
exposure:
include: health,info,metrics,prometheus,loggersRemember that the YAML value is a plain string here. A few rules apply.
include: "*"exposes every enabled endpoint. In YAML you must quote the asterisk, because an unquoted*is parsed as an alias marker and the file fails to load.excludewins overinclude. You can writeinclude: "*"and thenexclude: env,beans,heapdumpto expose everything except a few risky endpoints.- If you set
include, it replaces the default list. Settinginclude: metricsremoveshealthfrom HTTP unless you list it as well.
A useful pattern is to be explicit in production and permissive in local profiles.
management:
endpoints:
web:
exposure:
include: health,info,prometheus
---
spring:
config:
activate:
on-profile: dev
management:
endpoints:
web:
exposure:
include: "*"The same settings work in application.properties, where no quoting is needed:
management.endpoints.web.exposure.include=*
management.endpoints.web.exposure.exclude=heapdump,envExposure is not security
Exposing an endpoint only makes it routable. It says nothing about who may call it. If Spring Security is not on the classpath, an exposed endpoint is open to anyone who can reach the port. If Spring Security is on the classpath, Boot secures all endpoints except health by default with its standard configuration, but you should still define explicit rules. A later chapter covers this.
Enabling and disabling individual endpoints
Use management.endpoint.<id>.enabled to switch a single endpoint on or off. Note the singular endpoint, which differs from the plural endpoints used for exposure.
management:
endpoint:
shutdown:
enabled: true
beans:
enabled: falseTo flip the default for all endpoints, use management.endpoints.enabled-by-default.
management:
endpoints:
enabled-by-default: false
endpoint:
health:
enabled: true
info:
enabled: true
prometheus:
enabled: trueThis opt-in model is the strictest option. Only the three named endpoints are created, and no other bean exists to be exposed by mistake.
The shutdown endpoint deserves care. It accepts a POST to /actuator/shutdown and stops the application. To use it, you must both enable it and expose it, and you should secure it.
Newer Boot versions (3.4 and later) also let you control the level of access for each endpoint. The property management.endpoint.<id>.access accepts none, read-only, or unrestricted. If you use an older version, stay with the enabled property. Check your version's reference documentation before choosing.
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 connect to it and show MBeans, which are managed objects. Actuator publishes each endpoint as an MBean under the domain org.springframework.boot.
JMX exposure has its own properties.
management:
endpoints:
jmx:
exposure:
include: health,info
exclude: "*"In practice you choose either include or exclude. A typical locked-down setup lists only what is needed:
management:
endpoints:
jmx:
exposure:
include: health,loggersIn Boot 3.x, JMX support is not switched on automatically, so you must turn it on:
spring:
jmx:
enabled: trueThen run the application and connect with JConsole by running jconsole from the JDK. Open the MBean tab and find org.springframework.boot > Endpoint. Each endpoint appears as an MBean with operations you can invoke, such as health or configureLogLevel on the Loggers MBean.
JMX is often a good fit when you want to inspect an application from the same host without opening any network port. Remote JMX needs its own authentication and TLS setup, which is outside this chapter. Treat it with the same care as HTTP exposure.
Web endpoint paths and mapping
By default, an endpoint with ID metrics is served at /actuator/metrics. Two settings change this.
management.endpoints.web.base-pathchanges the/actuatorprefix.management.endpoints.web.path-mapping.<id>renames one endpoint.
management:
endpoints:
web:
base-path: /manage
path-mapping:
health: statusWith this configuration, health is served at /manage/status. The next chapters and the management server chapter build on this idea.
Caching of read operations
Read operations that take no parameters can be cached. Set management.endpoint.<id>.cache.time-to-live, for example management.endpoint.beans.cache.time-to-live=10s. This protects expensive endpoints from being hit repeatedly. The default is zero, which means no caching.
Common errors
| Symptom | Likely cause | Fix |
|---|---|---|
| 404 on `/actuator/metrics` | Endpoint is enabled but not exposed | Add `metrics` to `management.endpoints.web.exposure.include` |
| `/actuator/health` disappeared after setting `include` | `include` replaces the default list | List `health` explicitly |
| Application fails to start with a YAML parse error | Unquoted `*` | Write `include: "*"` |
| 404 on `/actuator/shutdown` | Disabled by default | Enable and expose it, and secure it |
| 404 on `/actuator/prometheus` | Registry dependency missing | Add `micrometer-registry-prometheus` |
| Setting has no effect | Used `endpoint` where `endpoints` is needed, or the reverse | Use `management.endpoint.<id>` for one endpoint and `management.endpoints.*` for global rules |
Checking your configuration
Use this short configuration and confirm each behavior with curl.
management:
endpoints:
web:
exposure:
include: health,info,metrics
exclude: infoBecause exclude wins, only health and metrics are reachable. A request to /actuator/info returns 404 even though info is in the include list.
Exercise
An application sets management.endpoints.web.exposure.include=metrics. A developer then reports that /actuator/health returns 404, although health is enabled by default. Explain why, and give the property value that restores health while keeping metrics.
Show answer
The include property replaces the default exposure list, which contained only health. After the change, only metrics is exposed over HTTP. Health is still enabled, but it is no longer exposed. Setting management.endpoints.web.exposure.include=health,metrics restores it.
Exercise
You want every endpoint reachable in a development profile except heapdump and env. Write the YAML properties that do this, and explain what happens if you forget to quote the asterisk.
Show answer
Use management.endpoints.web.exposure.include: "*" with management.endpoints.web.exposure.exclude: heapdump,env. Exclusion takes priority over inclusion, so the two endpoints stay hidden. An unquoted * is read by YAML as an alias indicator, so the file fails to parse and the application does not start.