什么是 Spring Boot Admin(SBA)?
Spring Boot Admin 是 codecentric 公司开发的一款开源社区项目,目标是让用户更方便的管理以及监控 Spring Boot ® 应用。 应用可以通过我们的Spring Boot Admin客户端(通过HTTP的方式)或者使用Spring Cloud ®(比如Eureka,consul的方式)注册。 基于Spring Boot Actuator默认接口开发的。
本文使用nacos作为注册中心,实现客户端通过nacos注册到服务端。
 使用注册中心注册的好处在于,客户端无感知就能被监控。
2.1. 配置SBA服务端应用程序
第一步配置你的服务端程序
-  将Spring Boot Admin Server的starter添加到你的依赖中: pom.xml <dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-starter-server</artifactId> <version>2.7.10</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <!--引入Nacos依赖--> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId> <version>2021.0.1.0</version> </dependency>服务端的spring boot版本为2.7.0 - 在main class上添加@EnableAdminServer注解,启用SBA服务器端配置:
 @Configuration @EnableAutoConfiguration @EnableAdminServer public class SpringBootAdminApplication { public static void main(String[] args) { SpringApplication.run(SpringBootAdminApplication.class, args); } }
- 在main class上添加
-  配置Nacos地址 
application.yml
spring:  
  cloud:  
    nacos:  
      discovery:  
        server-addr: 127.0.0.1:8858  
  application:  
    name: admin-server  
server:  
  port: 9001    
management:  
  endpoint:  
    health:  
      enabled: true
- 服务端的配置就完成了。开始启动服务端。访问:http://localhost:9001/wallboard

 可以看到服务端本身的实例信息。现在我们来配置客户端,让客户端通过nacos注册上来。
3.1. 配置SBA客户端应用程序
第一步配置你的客户端程序
将Spring Boot Admin Client的starter添加到你的依赖中:
<dependency>  
    <groupId>org.springframework.boot</groupId>  
    <artifactId>spring-boot-starter-web</artifactId>  
</dependency>  
  
<!--actuator必须引入,监控数据来源于actuator-->  
<dependency>  
    <groupId>org.springframework.boot</groupId>  
    <artifactId>spring-boot-starter-actuator</artifactId>  
</dependency>  
<!--引入Nacos依赖-->  
<dependency>  
    <groupId>com.alibaba.cloud</groupId>  
    <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>  
    <version>2021.0.1.0</version>  
</dependency>
配置nacos地址:
application.yml
spring:  
  cloud:  
    nacos:  
      discovery:  
        server-addr: localhost:8858  
  application:  
    name: admin-client  
server:  
  port: 7888  
management:  
  endpoints:  
    web:  
      exposure:  
        include: '*'  
  endpoint:  
    health:  
      show-details: NEVER
配置完成。启动客户端程序。

可以看到服务端跟客户端都注册上来了。
可以查看实例的监控情况下面随便贴几张监控图:


 感兴趣的可以自己搭建一个demo试试。上手非常简单。
有疑问的朋友欢迎在文章下方提问,有关于SBA各种使用问题均能解答。
本文使用到的依赖版本情况:
- Spring Boot version : 2.7.0
- spring-boot-admin version : 2.7.10
- nacos discovery version : 2021.0.1.0



















