开始使用Spring Boot Admin(SBA)吧-使用Nacos注册SBA

什么是 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服务端应用程序

第一步配置你的服务端程序

  1. 将Spring Boot Admin Server的starter添加到你的依赖中:

    pom.xml

    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
    2. 在main class上添加@EnableAdminServer注解,启用SBA服务器端配置:

    less 复制代码
    @Configuration
    @EnableAutoConfiguration
    @EnableAdminServer
    public class SpringBootAdminApplication {
        public static void main(String[] args) {
            SpringApplication.run(SpringBootAdminApplication.class, args);
        }
    }
  2. 配置Nacos地址

application.yml

yaml 复制代码
spring:  
  cloud:  
    nacos:  
      discovery:  
        server-addr: 127.0.0.1:8858  
  application:  
    name: admin-server  
server:  
  port: 9001    
management:  
  endpoint:  
    health:  
      enabled: true
  1. 服务端的配置就完成了。开始启动服务端。访问:http://localhost:9001/wallboard

可以看到服务端本身的实例信息。现在我们来配置客户端,让客户端通过nacos注册上来。

3.1. 配置SBA客户端应用程序

第一步配置你的客户端程序

将Spring Boot Admin Client的starter添加到你的依赖中:

xml 复制代码
<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

yaml 复制代码
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
相关推荐
实名上网宋凯宣9 小时前
Django
后端·python·django
利威尔xu11 小时前
Go IM 源码实战(14):本地缓存快 3000 倍,失效却难 10 倍
后端·缓存·微服务·面试·golang
逃逸线LOF11 小时前
Ribbon负载均衡原理(Irule组件、源码分析)
后端·spring cloud·ribbon
慢云智慧空间12 小时前
从设备智能到空间理解,空间智能终端解决方案商如何重新定义行业标准
后端
利威尔xu12 小时前
Go IM 源码实战(13):30 个会话只有 2 个红点,未读数错在三条路径
redis·后端·微服务·面试·golang
薛定谔的猫-菜鸟程序员12 小时前
软件架构设计师开发资料大全(从入门到精通)
后端·python·系统架构·flask·架构设计师
云创智城-yuncitys13 小时前
YunParking 4.0:JDK 17 与 Spring Boot 3.2 的停车云升级
java·开发语言·spring boot
IT_陈寒14 小时前
SpringBoot多环境配置把我坑惨了,这个踩坑经验你最好看看
前端·人工智能·后端
码事漫谈14 小时前
DeepSeek 搞了个 "Super-agent",但不是超级智能
后端
吴凡wudianmei14 小时前
从 0 搭一个 AI Agent(四):SSE 跑通之后,三处“契约错配”与它们的修复边界
前端·后端·aigc