Spring Boot - Admin Server



Monitoring your application by using Spring Boot Actuator Endpoint is slightly difficult. Because, if you have n number of applications, every application has separate actuator endpoints, thus making monitoring difficult. Spring Boot Admin Server is an application used to manage and monitor your Microservice application.

To handle such situations, CodeCentric Team provides a Spring Boot Admin UI to manage and monitor all your Spring Boot application Actuator endpoints at one place.

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-server</artifactId>
   <version>3.3.3</version>
</dependency>

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

compile group: 'de.codecentric', name: 'spring-boot-admin-starter-server', version: '3.3.3'

Creating Spring Admin Server

First, download the Spring Boot project from the Spring Initializer page and choose the Spring Admin Server and Admin Server UI dependency. Observe the screenshot given below −

Creating Spring Admin Server

Add the @EnableAdminServer annotation in your main Spring Boot application class file. The @EnableAdminServer annotation is used to make your as Admin Server to monitor all other microservices.

AdminserverApplication

package com.tutorialspoint.adminserver;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import de.codecentric.boot.admin.config.EnableAdminServer;

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

Now, define the server.port and application name in application.properties file a shown −

server.port = 9090
spring.application.name = adminserver

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

server:
   port: 9090
spring:
   application:
      name: adminserver

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>adminserver</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>de.codecentric</groupId>
         <artifactId>spring-boot-admin-starter-server</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 group: 'de.codecentric', name: 'spring-boot-admin-server', 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 −


  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/

[32m :: Spring Boot :: [39m              [2m (v3.3.3)[0;39m

[2m2024-09-12T16:16:44.507+05:30[0;39m [32m INFO[0;39m [35m18380[0;39m [2m---[0;39m [2m[adminserver] [           main][0;39m [2m[0;39m[36mc.t.adminserver.AdminserverApplication  [0;39m [2m:[0;39m Starting AdminserverApplication using Java 21.0.3 with PID 18380 (E:\Dev\adminserver\target\classes started by Tutorialspoint in E:\Dev\adminserver)
[2m2024-09-12T16:16:44.510+05:30[0;39m [32m INFO[0;39m [35m18380[0;39m [2m---[0;39m [2m[adminserver] [           main][0;39m [2m[0;39m[36mc.t.adminserver.AdminserverApplication  [0;39m [2m:[0;39m No active profile set, falling back to 1 default profile: "default"
[2m2024-09-12T16:16:45.909+05:30[0;39m [33m WARN[0;39m [35m18380[0;39m [2m---[0;39m [2m[adminserver] [           main][0;39m [2m[0;39m[36mion$DefaultTemplateResolverConfiguration[0;39m [2m:[0;39m Cannot find template location: classpath:/templates/ (please add some templates, check your Thymeleaf configuration, or set spring.thymeleaf.check-template-location=false)
[2m2024-09-12T16:16:46.179+05:30[0;39m [32m INFO[0;39m [35m18380[0;39m [2m---[0;39m [2m[adminserver] [           main][0;39m [2m[0;39m[36mo.s.b.a.e.web.EndpointLinksResolver     [0;39m [2m:[0;39m Exposing 1 endpoint beneath base path '/actuator'
[2m2024-09-12T16:16:46.867+05:30[0;39m [32m INFO[0;39m [35m18380[0;39m [2m---[0;39m [2m[adminserver] [           main][0;39m [2m[0;39m[36mo.s.b.web.embedded.netty.NettyWebServer [0;39m [2m:[0;39m Netty started on port 9090 (http)
[2m2024-09-12T16:16:46.881+05:30[0;39m [32m INFO[0;39m [35m18380[0;39m [2m---[0;39m [2m[adminserver] [           main][0;39m [2m[0;39m[36mc.t.adminserver.AdminserverApplication  [0;39m [2m:[0;39m Started AdminserverApplication in 2.702 seconds (process running for 3.754)

Now hit the below URL from your web browser and see the Admin Server UI.

http://localhost:9090/

Web Browser Admin Server UI
Advertisements