Spring Boot has no PrometheusTemplate class. The component that does this job is Micrometer's PrometheusMeterRegistry, which Spring Boot Actuator creates for you when micrometer-registry-prometheus is on the classpath. It collects every meter in the application and renders it in the Prometheus text format at /actuator/prometheus.
If you found PrometheusTemplate in an older tutorial or an AI-generated answer, treat it as an error: the real API is MeterRegistry for recording metrics and PrometheusMeterRegistry for exposing them.
Three pieces work together in a Spring Boot application:
| Piece | Role |
|---|---|
Micrometer (MeterRegistry) | Vendor-neutral metrics facade: counters, gauges, timers, distribution summaries |
PrometheusMeterRegistry | The Micrometer registry that stores meters and formats them for Prometheus |
Actuator prometheus endpoint | HTTP endpoint at /actuator/prometheus that Prometheus scrapes |
Prometheus works by pulling: the server calls the endpoint on a schedule (for example every 15 seconds) and stores the returned samples. Your application never pushes data, so there is no template or client object to call for sending.
Add Actuator and the Prometheus registry. With Maven:
Spring Boot manages the version of both, so you do not set one. Then expose the endpoint in application.properties:
Start the application and open http://localhost:8080/actuator/prometheus. You will see JVM, CPU, memory, thread, HTTP server and datasource metrics without writing any code.
Note that newer Micrometer versions moved to the Prometheus client 1.x library, and the older client is available as a separate micrometer-registry-prometheus-simpleclient artifact. For a new project, use the default dependency above and let Spring Boot's dependency management pick the matching versions.
To publish your own numbers, inject MeterRegistry, not a Prometheus-specific class. The code stays portable if you later switch to another monitoring system.
On the Prometheus endpoint, Micrometer converts the names to Prometheus conventions: dots become underscores and counters get a _total suffix.
A gauge reports a value that goes up and down, such as a queue size:
You can also time methods declaratively with @Timed, but it only works when you register the aspect:
Point Prometheus at the endpoint in prometheus.yml:
On Kubernetes, use service discovery or the Prometheus Operator's ServiceMonitor instead of static targets. Secure the endpoint in production: expose it on a separate management port (management.server.port=9090) or restrict it with Spring Security so that only the monitoring system can reach it.
Because scraping needs a long-running process, a batch job that exits quickly may be gone before Prometheus asks. Spring Boot supports the Prometheus Pushgateway for that case through management.prometheus.metrics.export.pushgateway.enabled=true and the related base-url and job properties (check the property names for your Boot version, which changed between 2.x and 3.x). Use it only for short-lived jobs, not for regular services.
No. Neither Spring Boot, Spring Framework nor Micrometer ships a class with that name. Use MeterRegistry to record metrics and the Actuator prometheus endpoint to expose them.
Add micrometer-registry-prometheus, expose the prometheus endpoint and add a scrape job that targets /actuator/prometheus.
Micrometer is the instrumentation library inside your application. Prometheus is the external system that scrapes and stores the numbers. PrometheusMeterRegistry is the adapter between them.
Usually the endpoint is not exposed. Check that management.endpoints.web.exposure.include contains prometheus and that the registry dependency is on the runtime classpath.
There is no PrometheusTemplate. In Spring Boot, record metrics through MeterRegistry, let PrometheusMeterRegistry format them, and let Prometheus scrape /actuator/prometheus. Add the Actuator and Micrometer Prometheus dependencies, expose the endpoint, protect it in production, and use the Pushgateway only for short-lived jobs.