This post delves into the Spring Boot Actuator, which provides endpoints to monitor and interact with a Spring Boot application. The Spring Boot Actuator exposes endpoints through both JMX (Java Management Extensions) and HTTP. Although JMX endpoints are available, HTTP endpoints are commonly utilized in Spring Boot applications for monitoring purposes. The Spring Boot Actuator contributes to the effective monitoring and management of Spring Boot applications. These built-in endpoints are supplied by the Actuator and can be exposed or configured using the application’s application.properties file.

Spring Boot Actuator

The Spring Boot Actuator can be activated by including the necessary dependencies in the pom.xml file. Specifically, the spring-boot-starter-actuator dependency should be added to the project’s pom.xml file. This can be selected during the creation of a Spring Boot starter project in the Spring Tool Suite. Additionally, to expose the Actuator endpoints, the spring-web module should be included alongside the Spring Boot Actuator project. The endpoint RESTful web services are then exposed using the Tomcat web server.

pom.xml

	<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>
                .....................
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
		</dependency>
	</dependencies>

When you launch the Spring Boot application with the specified dependencies, the Spring Boot Actuator will be automatically enabled with default endpoints. By default, two endpoints are exposed:

  1. www.localhost:8080/actuator: This endpoint returns a list of all exposed actuator endpoints.

  2. www.localhost:8080/actuator/health: The health endpoint displays the health status of the Spring Boot application.

These endpoints provide valuable information and are part of the Spring Boot Actuator’s functionality for monitoring and managing the application.

Enable info endpoint

If you want to enable the info endpoint in a Spring Boot application using the application.properties file, you can add the following configuration. This configuration explicitly includes the info endpoint for exposure through the web. After adding this line to your application.properties file, the info endpoint will be enabled and accessible in your Spring Boot application.

application.properties

management.endpoints.web.exposure.include=info,health
management.info.env.enabled=true

info.app.name=Sample Applicatin for Spring Boot Actuator
info.app.java.version=17
info.app.type=Spring Boot Actuator Endpoint

To access comprehensive information through the info endpoint, include the following configuration in the application.properties file. The info endpoint offers details encompassing the application environment, Java version, operating system details, build information, and more. The resulting information endpoint will be displayed as depicted below.

management.endpoints.web.exposure.include=info,health
management.info.env.enabled=true
management.info.os.enabled=true
management.info.java.enabled=true
management.info.defaults.enabled=true
management.info.git.enabled=true
management.info.build.enabled=true

info.app.name=Sample Applicatin for Spring Boot Actuator
info.app.java.version=17
info.app.type=Spring Boot Actuator Endpoint

Exposing All Actuator Endpoints

Enabling all endpoints in Spring Boot can be achieved by configuring with the “*” wildcard option. To showcase all available endpoints, the configuration in the application.properties file should be modified to include all options. This ensures that every available endpoint is exposed and accessible.

application.properties

management.endpoints.web.exposure.include=*

In Spring Boot, you can configure specific endpoints in the configuration by using comma-separated values. The endpoints should be listed, separated by commas. The following example illustrates how to configure a list of endpoints to enable in the Spring Boot application.

management.endpoints.web.exposure.include=info,health,bean,env

Exposing Actuator Endpoints with Spring Boot Security

The Spring Boot security module facilitates the exposure of actuator endpoints for usage after undergoing security validation. This module utilizes a login username and password to authenticate access to the endpoints. Users must provide their credentials, including a valid username and password, to gain entry to the endpoint. The actuator endpoint URLs become accessible only if the provided login credentials are correct; otherwise, access to the endpoints is restricted.

pom.xml

	<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>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-security</artifactId>
		</dependency>

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
		</dependency>
	</dependencies>

application.properties

spring.security.user.name=testuser
spring.security.user.password=password

management.endpoints.web.exposure.include=info,health,bean,env

Leave a Reply