Open In App

Spring Boot – Admin Client

Last Updated : 20 Feb, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

In Sprint Boot, Admin and Client can be implemented so that the client can be registered with the server, and then the server maintains the client’s service health and availability, scales up the service, and also measures the representation of the client.

Spring Boot Admin Server

The Admin Server can represent the UI dashboard of the Spring Boot applications, and it can monitor an application and represent the dashboard metrics of the client server’s health.

Key Terminologies:

  • Admin Server: The spring boot server is an application that can provide a web-based UI for managing and monitoring the spring boot applications.
  • Instances: These can be defined as the individual spring boot applications that are registered with the spring boot admin server.
  • Application Registry: It is a central registry maintained by the Springboot admin server that keeps track of registered client applications.
  • Event Bus: It is a mechanism for broadcasting events from the spring boot and admin server to connect clients. It is used to provide real-time updates to the UI.

Spring Boot Admin Client

Spring Boot Admin Client is a simple spring boot application that includes the spring boot client library and allows the application to register with the spring boot admin server for monitoring and managing the service.

Key Terminologies:

  • Admin Client: It is a Spring Boot Admin Client Library that allows the application to register with the Spring Boot admin server.
  • Registration: It can be the process by which a client application registers with the admin application, and it’s responsible for providing monitoring information.
  • Actuator Endpoints: Spring Boot Actuator exposes various information about the application, such as health, metrics, and environment details.
  • Health Indicator: It is a component that provides information about the benefits of the spring boot application.

Step-by-Step Implementation of Admin Client in Spring Boot

Step 1: Create the project named GFGSpringClientDemo and add the dependencies and choose tool gradle or maven. We chose Gradle, then created the project and opened it.

  • Project Name: GFGSpringClientDemo
  • Type: Gradle-Groovy
  • Packaging: Jar
  • Language: Java
  • Version: 17

Project Structure:

Project Structure

Step 2: Once created the project after that open the application.properities file then configure the admin client and URL and endpoints exposure please refer the code.

spring.boot.admin.client.url=http://localhost:8082
management.endpoints.web.exposure.include=*
management.endpoint.health.show-details=always

Below we can refer to the main class file:

Java




package in.gfg.demo;
  
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
  
@SpringBootApplication
  
public class GfgSpringClientDemoApplication {
  
    public static void main(String[] args) {
        SpringApplication.run(GfgSpringClientDemoApplication.class, args);
    }
}


The Spring Admin Client configuration is complete and now configure the server and after that run the server and client then open the Spring Admin server dashboard it shows the Spring Admin Client Information.

Step 3: Create another project named GFGSpringAdminDemo and add the dependencies and open it into the Spring STS IDE.

  • Package Name: in.gfg.demo
  • Dependencies: codecentric’s Spring Boot Admin (Admin), Spring Boot Actuator, Spring dev tools

Step 4: Once complete the project creation open the application.properities file and added the below server port configuration code.

server.port: 8083

Project file Structure of GFGSpringAdminDemo:

Directory Structure

Step 5: After that open the Spring Boot application main code then the enable annotation into the of the EnableAdminSever. After that save the project and run it and checks if error occurs or not.

Java




package in.gfg.demo;
  
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
  
import de.codecentric.boot.admin.server.config.EnableAdminServer;
  
@SpringBootApplication
@EnableAdminServer
public class GfgSpringAdminDemoApplication {
  
    public static void main(String[] args) {
        SpringApplication.run(GfgSpringAdminDemoApplication.class, args);
    }
}


The Spring Boot Admin Server configuration is also completed here you need to observe one thing can enable the Spring Boot Admin Server on the Spring Boot main method.

  • @EnableAdminServer: This annotation can be used to enable the Spring Boot Admin Server into the spring boot application, and it can enable the spring boot admin Server web-based UI dashboard

Step 6: Both Admin and server configuration is completed after that can be run the spring boot server application and after that run the spring boot admin client application and here that spring admin client can register into the Admin Server and manages and maintain the health of the spring Boot Admin Client.

Output:

Output Screen

In the above picture, we can find out the spring-boot-application it can be shown into the spring boot admin server UI dashboard. It can monitor and manages the spring boot admin client of the spring boot project.

Register Information

The above picture shows the register information of the spring admin server client application into the spring boot admin server web-based UI dashboard.



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads