Spring Boot Actuator and Dev Tools
In the previous article, we learned about Setting up spring security and Swagger-UI in Spring boot. (Setting Up Spring Security and Swagger-UI)
What you will learn from this blog?
Using Spring Boot Actuator
Using Spring Boot Dev Tools
Spring Boot Actuator
Spring Boot Actuator is a sub-project of Spring Boot which adds several production-ready services to our applications.
To look further, Let us create a Spring Boot Application using Spring initializr.
We have added the Spring Web, Spring Boot Actuator and Spring Boot DevTools dependencies.
Spring Boot Actuator, Provides several endpoints out of which only /health is enabled by default. We can see all the enabled URLs using the actuator URL below.
The /health endpoint provides us with the application running status.
We can enable the other end-points provided by the actuator using the below property in the application.properties file.
use the property management.endpoints.web.exposure.include=* and invoke the actuator endpoint to view the endpoints that are provided.
We can also enable only a few endpoints by using the include property and similarly exclude a few endpoints using the exclude property.
management.endpoints.web.exposure.include=health,info management.endpoints.web.exposure.exclude=env,beans
endpoints | Description |
/auditevents | Exposes audit events information for the current application. Requires an |
/beans | Displays a complete list of all the Spring 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 |
/env | Exposes properties from Spring’s |
/health | Shows application health information. |
/info | Displays arbitrary application info. |
/loggers | Shows and modifies the configuration of loggers in the application. |
/metrics | Shows “metrics” information for the current application. |
/shutdown | Lets the application be gracefully shut down. Disabled by default. |
The table above provides some of the most used endpoints of actuators.
By using the below properties, We can define a separate port for actuator endpoints and application endpoints.
The Actuator endpoints will be exposed on 9001 and the application endpoints on 9000.
Spring Boot DevTools
We can enable the DevTools by adding the below dependency in pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
Spring Boot Dev Tools provide us with various features out of which we will be learning the most used features.
DevTools are built only for development-specific purposes and it gets auto-disabled in the production environment/setting.
Property Defaults
Spring Boot does a lot of auto-configurations including caching to improve performance, One such example is caching of templates while using thymeleaf.
But during the development, We need to refresh the cache each time when there is a change which can be easily done by using Dev Tools.
Auto Restart
In Development Environment, We do frequent changes to the code and would need to restart the embedded server each time to validate the changes.
DevTools provides the capability of Auto restart and whenever there is a change in the code the server gets restarted.
To test this feature, start the server and change the code. Try to compile the project in another terminal using mvn compile, the server will restart as shown below.
If the build project automatically option is enabled in the IDE, then the code changes will result in the compilation of classes and the server gets restarted automatically.
Live Reload
Spring Boot Dev Tools provides a Live reload server which is used to trigger the browser refresh whenever there is a change in the resource.
For this to happen we need to install the Live reload plugin in the browser. This feature is mostly used for UI changes.
Global Settings
Spring Boot Dev Tools provides us with the option to group our favourite configuration in a file that can be reused for various projects.
We can define the global config file in the system users home directory with the following name .spring-boot-devtools.properties
Finally, We have understood the benefits of Spring Boot Actuator and Dev Tools. We are also able to integrate and test some of its features.
The source code is available on GitHub mentioned below
You can follow me on Twitter and Linkedin to stay updated with my blogs. Happy Learning .. 😊👍
Subscribe to my newsletter
Read articles from Hithesh Sampathi directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Hithesh Sampathi
Hithesh Sampathi
I am a Software developer