Spring Boot Actuator Example

By | 2018-08-12T09:26:23+00:00 August 12th, 2018|Spring Boot|0 Comments

In this tutorials, we are going to see what is Spring Boot Actuator and how it is useful to our production release applications.

Spring Boot Actuator:

Actuator is a sub-project of Spring Boot. It brings production-ready features of our application. It is mainly used to expose operational information about the running application such as :

The health of the application, metrics, loggings, dumps, env and etc. It typically uses HTTP endpoints to enable us to interact with it.

Advantages of Spring Boot Actuator:

  • It allows us to monitor our application
  • To gather the application’s metrics
  • Understand the real traffic
  • We can get the production grade tools via the HTTP end pints, by making use of these we can get the above information and we are also free to configure and extend these features in many ways.

Setting Spring Boot Actuator:

The simplest way to enable the actuator feature in our application is to add the spring-boot-starter-actuator ‘Starter’. This dependency provides all of the Spring Boot’s production-ready features.

To add the actuator to a Maven based project, add the following ‘Starter’ dependency:

Actuator Maven Dependency

Technologies Used:

  • spring-boot-starter-parent-2.0.4 RELEASE
  • spring-boot-starter-actuator
  • Java8
  • IntelliJ IDEA

Spring Boot Actuator 2.x version:

  • If you are familiar with actuator 1.x versions, most of the actuator endpoints were available.
  • Comming to the actuator 2.x versions, Actuator comes with most of the endpoints disabled.
  • Would we want to enable all of them at a time, we should set management.endpoints.web.exposure.include=* property in application.properties file.

You can find the further details about the 2.x version in the official document

Java Config to enable all actuator endpoints
public SecurityWebFilterChain securityWebFilterChain(
  ServerHttpSecurity http) {
    return http.authorizeExchange()

Default endpoints:

Actuator Default Endpoints
/auditevents – Exposes audit events information for the current application.
/beans – returns all available beans in your application
/conditions – Shows the conditions that were evaluated on configuration and auto-configuration classes and the reasons why they did or did not match
/configprops – Displays a collated list of all @ConfigurationProperties beans.
/env – returns the current environment properties.Properties from Spring’s ConfigurableEnvironment.
/flyway – provides details about our Flyway database migrations
/health – shows the health status of our application
/heapdump – returns a GZip compressed hprof heap dump file of yor application.
/info – returns general information about the application. It might be custom data, build information or details about the latest commit
/liquibase – Shows any Liquibase database migrations that have been applied.
/logfile – Returns the contents of the logfile (if logging.file or logging.path properties have been set).
/loggers – enables us to query and modify the logging level of our application
/metrics – details metrics of our current application. This might include generic metrics as well as custom ones
/prometheus – exposes metrics in a format that can be scraped by a Prometheus server.
/scheduledtasks – provides details about every scheduled task within our application
/sessions – Allows retrieval and deletion of user sessions from a Spring Session-backed session store. It may not available when using Spring Session’s support for reactive web applications
/shutdown – performs a graceful shutdown of the application
/threaddump – dumps the thread information of the underlying JVM

Spring Boot Actuator Example:

Spring Boot Actuator Example

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">


  <description>Demo project for Spring Boot</description>

    <relativePath/> <!-- lookup parent from repository -->


Confugure server port, actuator port and enabling all default actuator endpoints.
server.port: 9000 
management.server.port: 9001 
Note: Our actuator is running under 9001 port.
package com.onlinetutorialspoint;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

public class HelloController {

    public String hello(@RequestParam(name="name",required = false,defaultValue = "user") String name){
        return "hello "+name+" :)";
package com.onlinetutorialspoint;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.PropertySource;

public class SpringBootActuatorApplication {

  public static void main(String[] args) {
      SpringApplication.run(SpringBootActuatorApplication.class, args);

Run Application:

E:\work\SpringBoot-Actuator-Example>mvn spring-boot:run
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building SpringBoot-Actuator-Example 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] >>> spring-boot-maven-plugin:2.0.4.RELEASE:run (default-cli) > test-compile @ SpringBoot-Actuator-Example >>>
[INFO] --- maven-resources-plugin:3.0.2:resources (default-resources) @ SpringBoot-Actuator-Example ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 0 resource
[INFO] --- maven-compiler-plugin:3.7.0:compile (default-compile) @ SpringBoot-Actuator-Example ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 2 source files to E:\work\SpringBoot-Actuator-Example\target\classes
[INFO] --- maven-resources-plugin:3.0.2:testResources (default-testResources) @ SpringBoot-Actuator-Example ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory E:\work\SpringBoot-Actuator-Example\src\test\resources
[INFO] --- maven-compiler-plugin:3.7.0:testCompile (default-testCompile) @ SpringBoot-Actuator-Example ---
[INFO] Nothing to compile - all classes are up to date
[INFO] <<< spring-boot-maven-plugin:2.0.4.RELEASE:run (default-cli) < test-compile @ SpringBoot-Actuator-Example <<<
[INFO] --- spring-boot-maven-plugin:2.0.4.RELEASE:run (default-cli) @ SpringBoot-Actuator-Example ---

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 :: Spring Boot ::        (v2.0.4.RELEASE)

2018-08-12 08:42:59.223  INFO 6280 --- [           main] c.o.SpringBootActuatorApplication        : Starting SpringBootActuatorApplication on DESKTOP-RN4SMHT with PID 6280 (E:\work\S
pringBoot-Actuator-Example\target\classes started by Lenovo in E:\work\SpringBoot-Actuator-Example)
2018-08-12 08:42:59.239  INFO 6280 --- [           main] c.o.SpringBootActuatorApplication        : No active profile set, falling back to default profiles: default
2018-08-12 08:42:59.444  INFO 6280 --- [           main] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWeb
ServerApplicationContext@4f1d523f: startup date [Sun Aug 12 08:42:59 IST 2018]; root of context hierarchy
2018-08-12 08:43:04.229  INFO 6280 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 9000 (http)
2018-08-12 08:43:04.338  INFO 6280 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2018-08-12 08:43:04.338  INFO 6280 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.32
2018-08-12 08:43:04.354  INFO 6280 --- [ost-startStop-1] o.a.catalina.core.AprLifecycleListener   : The APR based Apache Tomcat Native library which allows optimal performance in pro
duction environments was not found on the java.library.path: [C:\Program Files\Java\jdk1.8.0_161\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\ProgramData\Oracle\Java
\javapath;C:\oraclexe\app\oracle\product\11.2.0\server\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\
MySQL\MySQL Server 5.5\bin;C:\php;C:\Apache24;C:\Apache24\bin;C:\Program Files\Java\jdk1.8.0_161\bin;D:\Softwares\apache-maven-3.5.2\bin;C:\Program Files\Git\cmd;C:\Program Files\Git
\mingw64\bin;C:\Program Files\Git\usr\bin;D:\Softwares\apache-ant-1.10.2\bin;C:\ProgramData\chocolatey\bin;;C:\WINDOWS\System32\OpenSSH\;C:\Users\Lenovo\AppData\Local\Programs\Python
AppData\Local\Microsoft\WindowsApps;;C:\Program Files\Microsoft VS Code\bin;C:\Program Files\Docker Toolbox;.]
2018-08-12 08:43:04.620  INFO 6280 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2018-08-12 08:43:04.635  INFO 6280 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 5222 ms


Accessing Spring Boot Actuator endpoints:


Spring Boot Actuator Metrics


Spring Boot Actuator Health


Spring Boot Actuator heapdump

Happy Learning 🙂

Download Example

About the Author:

Hi Folks, you have reach this so far, that shows you like what you are learning. Then why don't you support us to improve for bettor tutorials by leaving your valuable comments and why not you keep in touch with us for latest updates on your favorite blog @ facebook , twitter , Or Google+ ,

Leave A Comment