Spring Boot Actuator includes a number of features related to runtime monitoring and managing of the application. We can use those features via HTTP endpoints or with JMX. In this tutorial we will see how to enable the actuator HTTP endpoints.
Actuator dependency
The dependency of spring-boot-starter-actuator should be included to enable the endpoints:
pom.xml<project .....> <modelVersion>4.0.0</modelVersion> <groupId>com.logicbig.example</groupId> <artifactId>enabling-actuator-end-point-example</artifactId> <version>1.0-SNAPSHOT</version> <packaging>war</packaging> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.0.1.RELEASE</version> </parent> <properties> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies> </project>
Enabling endpoints
To enable endpoints, we need to assigned their IDs to management.endpoints.web.exposure.include in application.properties. By default only 'health,info' is assigned (Boot 2.0.1.RELEASE). To enable all, '*' can be used.
src/main/resources/application.propertiesmanagement.endpoints.web.exposure.include=*
The boot main class
In this simple example we are not defining any MVC controllers. The boot main configuration class does not need anything special:
@SpringBootApplication
public class SpringBootMain {
public static void main(String[] args) {
SpringApplication.run(SpringBootMain.class);
}
}
Output
The enabled endpoints can be viewed at /actuator (hypermedia Response):
Accessing specific endpoints:
Other configuration properties
management.endpoints.web.exposure.exclude= # Endpoint IDs that should be excluded.
management.endpoints.web.base-path=/actuator # Base path for HTTP endpoints, default is /actuator.
management.endpoints.web.path-mapping= # Mapping between endpoint IDs and the path that should expose them, e.g. management.endpoints.web.path-mapping.health=healthcheck
Example ProjectDependencies and Technologies Used: - Spring Boot 2.0.1.RELEASE
Corresponding Spring Version 5.0.5.RELEASE - spring-boot-starter-actuator : Starter for using Spring Boot's Actuator which provides production
ready features to help you monitor and manage your application.
- spring-boot-starter-web : Starter for building web, including RESTful, applications using Spring
MVC. Uses Tomcat as the default embedded container.
- JDK 1.8
- Maven 3.3.9
|