使用Spring Boot Actuator Endpoint监控应用程序有点困难。因为,如果有’n’个应用程序,每个应用程序都有单独的执行器端点,从而使监控变得困难。Spring Boot Admin Server是一个用于管理和监控Microservice应用程序的程序。要处理这种情况,CodeCentric Team提供了一个Spring Boot Admin UI,用于在一个地方管理和监控所有Spring Boot应用程序Actuator端点。要构建Spring Boot Admin Server,需要在构建配置文件中添加以下依赖项。Maven用户可以在pom.xml 文件中添加以下依赖项 -
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-server</artifactId>
<version>1.5.5</version>
</dependency>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-server-ui</artifactId>
<version>1.5.5</version>
</dependency>
在主Spring Boot应用程序类文件中添加@EnableAdminServer注解。@EnableAdminServer注解用于使管理服务器监视所有其他微服务。
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);
}
}
现在,在application.properties文件中定义server.port和application.name
server.port = 9090
spring.application.name = adminserver
对于Maven用户,完整的构建文件 - 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
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.yiibai</groupId>
<artifactId>adminserver</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>adminserver</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-server</artifactId>
<version>1.5.5</version>
</dependency>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-server-ui</artifactId>
<version>1.5.5</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
现在,使用下面给出的命令运行JAR文件 -
java –jar <JARFILE>
现在,在Web浏览器中访问以下URL => http://localhost:9090/,然后查看管理服务器UI。