Spring Boot Admin: Initiation

Daniel S. Blanco
5 min readFeb 4, 2022

--

Today we are going to see a great application that will allow us to monitor our Spring Boot applications, Spring Boot Admin a.k.a SBA. This application has multiple qualities but in order to make use of them, first, we have to configure it. And in this post, we will focus on how to do it mainly, first with the default method and then making use of Eureka. For this, we have used the following versions:

  • Spring-boot: 2.5.7
  • Spring-admin: 2.5.4
  • Spring-cloud: 2020.0.3

To begin with, we will create a server that will be in charge of collecting the information and providing us with a graphical interface to access them.

We will start with a basic version. We will create a server that can register itself. For this we will have to follow the next steps:

  • Add the spring spring-boot-starter-web dependency.
  • Add the dependency of codecentric spring-boot-admin-starter-server that will contain the server engine.
  • Add the codecentric spring-boot-admin-starter-client dependency that will allow us to connect the server to itself.
  • Create the boot and configuration class with the annotations: @EnableAdminServer, @EnableAutoConfiguration, @SpringBootApplication.
  • Indicate through the spring.boot.admin.client.url property in the configuration file the path where our application will be. For example http://localhost:8080.
  • Indicate through the management.endpoints.web.exposure.include property the enablement of the Actuator endpoints.

We only have to start the application and we can see it displayed and auto-discovered.

With this, we will have the basic configuration, but we have to take into account that it is an application for the administration of other applications. And although in certain cases it can be deployed within an internal network where we will not have security problems. It is also possible that it will be deployed in production environments and therefore it must have some kind of security, especially if it is available from the Internet. To do this, we will add a basic configuration that allows us to include a login screen and a small user filter. And to carry it out we must carry out the following steps:

  • Add the spring-boot-starter-security library.
  • In the configuration file, we add the spring.security.user.name/passsword properties that configure a default user.
  • In the configuration file, we add the spring.boot.admin.client.username/password properties that allow the client, the same one, to log in to the server.
  • In the configuration file, we add the spring.boot.admin.client.instance.metadata.user.name/password properties that allow the server to access the client’s metrics-secured endpoints.
  • We also add a java security configuration class that allows unrestricted access to the info and health endpoints in addition to the login screen. Securing the rest of the URLs and endpoints of the application. Configuration obtained from the official documentation, here.

Now when trying to access the previous screen we will see the access form, in which we will have to indicate the user and password indicated in the configuration file:

Once we have the server deployed and secured. We are going to proceed to configure a client that can connect to the server. The configuration is very similar to the one we have seen before:

  • Add the spring-boot-admin-starter-client library.
  • In the configuration file, we add the spring.boot.admin.client.username/password properties that allow the client to log in to the server.
  • In the configuration file, indicate through the spring.boot.admin.client.url property, the path where our application will be.
  • In the configuration file, indicate through the management.endpoints.web.exposure.include property, the enabling of the Actuator endpoints.

And once we have started the new application, from the Applications tab of the SBA administration menu, we will be able to see which are the clients connected to it. In addition, by clicking on any of the clients, we will be able to see detailed information about that application.

But since we are in a world where microservices dominate the current landscape, we are now going to look at a slightly more modern configuration. Enabling the configuration through a Service Discovery like Eureka. To do this, we will create a Eureka server, you can see the example code here.

Once we have started the Eureka server, we will proceed to perform the necessary configuration on the SBA server. To do this we follow the next steps:

  • We add the spring-cloud-starter-netflix-eureka-client dependency, which will allow us to connect to the Eureka server. Therefore it is no longer necessary to use the spring-boot-admin-starter-client library, nor the properties with the spring.boot.admin suffix in the configuration file.
  • We add the spring-boot-starter-actuator dependency in case it is a passive dependency of another library.
  • In the configuration file, we indicate through the default URL of the server in the property eureka.client.serviceUrl.defaultZone.
  • In the configuration file, we enable Eureka to know the status of the application through the application’s health endpoint with the eureka.client.healthcheck.enabled property.
  • In the configuration file, we indicate the security credentials to access the secured endpoints through the eureka.instance.metadata-map.user.name/password properties. This step is only necessary if the endpoints are secured.

If we have followed the steps correctly both in the SBA server and in the clients, when accessing Eureka we will be able to visualize both of them:

And if we access the SBA server we will also be able to visualize both applications in it.

As always, if we have the concepts more or less clear, setting up an application with Spring Boot is quite simple. If you want access to the code visit the following link.

--

--

Responses (1)