Spring Boot - Admin Client



For monitoring and managing your microservice application via Spring Boot Admin Server, you should add the Spring Boot Admin starter client dependency and point out the Admin Server URI into the application properties file.

Note − For monitoring an application, you should enable the Spring Boot Actuator Endpoints for your Microservice application.

For building a Spring Boot Admin Server we need to add the below dependencies in your build configuration file.

Maven users can add the below dependencies in your pom.xml file −

<dependency>
   <groupId>de.codecentric</groupId>
   <artifactId>spring-boot-admin-starter-client</artifactId>
</dependency>
<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

Gradle users can add the below dependencies in your build.gradle file −

compile group: 'de.codecentric', name: 'spring-boot-admin-starter-client', version: '3.3.3'
compile('org.springframework.boot:spring-boot-starter-actuator')

Now, add the Spring Boot Admin Server URL into your application properties file.

For properties file users, add the following properties in the application.properties file.

spring.boot.admin.url = http://localhost:9090/

For YAML users, add the following property in application.yml file.

spring:
   boot:
      admin:
         url: http://localhost:9000/

Creating Spring Admin Client

First, download the Spring Boot project from the Spring Initializer page and choose the Spring Admin Client and Spring Boot Actuator. Observe the screenshot given below −

Creating Spring Admin Client

Following is Spring Boot main class.

AdminclientApplication.java

package com.tutorialspoint.adminclient;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class AdminclientApplication {
   public static void main(String[] args) {
      SpringApplication.run(AdminclientApplication.class, args);
   }
}

Now, define the admin server url in application.properties file a shown −

spring.boot.admin.url = http://localhost:9090/
spring.application.name = adminclient

For YAML users, use the following properties to define the port number and application name in application.yml file.

spring:
   application:
      name: adminserver
   boot:
      admin:
         url: http://localhost:9090/	  

The build configuration file is given below.

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
   <modelVersion>4.0.0</modelVersion>
   <parent>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-parent</artifactId>
      <version>3.3.3</version>
      <relativePath/> <!-- lookup parent from repository -->
   </parent>
   <groupId>com.tutorialspoint</groupId>
   <artifactId>adminclient</artifactId>
   <version>0.0.1-SNAPSHOT</version>
   <name>adminserver</name>
   <description>Demo project for Spring Boot</description>
   <url/>
   <licenses>
      <license/>
   </licenses>
   <developers>
      <developer/>
   </developers>
   <scm>
      <connection/>
      <developerConnection/>
      <tag/>
      <url/>
   </scm>
   <properties>
      <java.version>21</java.version>
      <spring-boot-admin.version>3.3.3</spring-boot-admin.version>
   </properties>
   <dependencies>
      <dependency>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter-actuator</artifactId>
      </dependency>
      <dependency>
         <groupId>de.codecentric</groupId>
         <artifactId>spring-boot-admin-starter-client</artifactId>
      </dependency>
      <dependency>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter-test</artifactId>
         <scope>test</scope>
      </dependency>
   </dependencies>
   <dependencyManagement>
      <dependencies>
         <dependency>
            <groupId>de.codecentric</groupId>
            <artifactId>spring-boot-admin-dependencies</artifactId>
            <version>${spring-boot-admin.version}</version>
            <type>pom</type>
            <scope>import</scope>
         </dependency>
      </dependencies>
   </dependencyManagement>
   <build>
      <plugins>
         <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
         </plugin>
      </plugins>
   </build>
</project>

For Gradle users build.gradle file

buildscript {
   ext {
      springBootVersion = '3.3.3'
   }
   repositories {
      mavenCentral()
   }
   dependencies {
      classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
   }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'

group = 'com.tutorialspoint'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 21
repositories {   
   mavenCentral()
}
dependencies {
   compile('org.springframework.boot:spring-boot-starter')
   compile('org.springframework.boot:spring-boot-starter-actuator')
   compile group: 'de.codecentric', name: 'spring-boot-admin-client', version: '3.3.3'
   testCompile('org.springframework.boot:spring-boot-starter-test')
}

Compilation and Execution

You can create an executable JAR file, and run the Spring Boot application by using the following Maven or Gradle commands −

For Maven, use the command shown here −

mvn clean install

After "BUILD SUCCESS", you can find the JAR file under target directory.

For Gradle, use the command shown here −

gradle clean build

After "BUILD SUCCESSFUL", you can find the JAR file under build/libs directory.

Now, run the JAR file by using the command given below −

java jar <JARFILE> 

Now, the application has started on the Tomcat port 9090 as shown here −


Now hit the following URL from your web browser and see your spring Boot application is registered with Spring Boot Admin Server.

http://localhost:9090/

Web Browser Admin Server

Now, click the Details button and the see the actuator endpoints in Admin Server UI.

Actuator Endpoints in Admin Server UI
Advertisements