Spring Cloud 学习 (八) Spring Boot Admin

2020-12-13 02:17

阅读:554

Spring Boot Admin 用于管理和监控一个或者多个 Spring Boot 程序

新建 spring-boot-admin-server

pom


    spring-cloud-parent
    com.karonda1.0.04.0.0

spring-boot-admin-server

de.codecentric
        spring-boot-admin-starter-server
        RELEASEorg.springframework.cloud
        spring-cloud-starter-netflix-eureka-client
    org.springframework.boot
            spring-boot-maven-plugin
        

spring-boot-admin-starter-server 需要指定版本号

application.yml

server:
  port: 8071

eureka:
  client:
    service-url:
      defaultZone: http://localhost:8001/eureka/

spring:
  application:
    name: admin-server

启动类

@EnableAdminServer // 开启 Admin Server
@EnableEurekaClient
@SpringBootApplication
public class AdminServerApp {
    public static void main(String[] args){
        SpringApplication.run(AdminServerApp.class, args);
    }
}

eureka-client

添加依赖

org.springframework.boot
    spring-boot-starter-actuator

注册 Spring Boot Admin (SBA) 客户端有两种方式:一种是通过引入 SBA Client (spring-boot-admin-starter-client);另一种是基于 Spring Cloud Discovery, 不需要添加依赖

application.xml 添加

management:
  endpoints:
    web:
      exposure:
        include: "*"
  endpoint:
    health:
      show-details: ALWAYS

测试

  1. 启动 eureka-server
  2. 启动 config-server
  3. 启动 eureka-client
  4. 启动 admin-server

访问 http://localhost:8071

完整代码:GitHub

本人 C# 转 Java 的 newbie, 如有错误或不足欢迎指正,谢谢

?


评论


亲,登录后才可以留言!