美文网首页
SpringBoot整合Spring Boot Admin

SpringBoot整合Spring Boot Admin

作者: 任未然 | 来源:发表于2022-01-04 11:04 被阅读0次

一. 概述

参考开源项目https://github.com/xkcoding/spring-boot-demo
SpringBoot服务启动了, 但怎么能直观的看到他的运行状态呢?本文将简单通过一个Demo,集成 Spring Boot Admin,并把自己的运行状态交给 Spring Boot Admin 进行展现。

二. 步骤

2.1 Admin 服务

2.1.1 依赖

  <dependencies>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <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>

2.1.2 application.yml

server:
  port: 8000

2.1.3 启动类

@EnableAdminServer
@SpringBootApplication
public class SpringBootDemoAdminServerApplication {

    public static void main(String[] args) {
        SpringApplication.run(SpringBootDemoAdminServerApplication.class, args);
    }
}

2.2 客户端

2.2.1 依赖

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
      <groupId>de.codecentric</groupId>
      <artifactId>spring-boot-admin-starter-client</artifactId>
    </dependency>

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-test</artifactId>
      <scope>test</scope>
    </dependency>

2.2.2 application.yml

server:
  port: 8080
  servlet:
    context-path: /demo
spring:
  application:
    # Spring Boot Admin展示的客户端项目名,不设置,会使用自动生成的随机id
    name: spring-boot-demo-admin-client
  boot:
    admin:
      client:
        # Spring Boot Admin 服务端地址
        url: "http://localhost:8000/"
#        instance:
#          metadata:
#            # 客户端端点信息的安全认证信息
#            user.name: ${spring.security.user.name}
#            user.password: ${spring.security.user.password}
#  security:
#    user:
#      name: demo
#      password: 123456
management:
  endpoint:
    health:
      # 端点健康情况,默认值"never",设置为"always"可以显示硬盘使用情况和线程情况
      show-details: always
  endpoints:
    web:
      exposure:
        # 设置端点暴露的哪些内容,默认["health","info"],设置"*"代表暴露所有可访问的端点
        include: "*"

2.2.3 启动类

@SpringBootApplication
public class SpringBootDemoAdminClientApplication {

    public static void main(String[] args) {
        SpringApplication.run(SpringBootDemoAdminClientApplication.class, args);
    }
}

2.3 启动服务

image.png

相关文章

网友评论

      本文标题:SpringBoot整合Spring Boot Admin

      本文链接:https://www.haomeiwen.com/subject/qydqcrtx.html