0
点赞
收藏
分享

微信扫一扫

SpringCloud 第十章:Spring Cloud Greenwich 版本集成Spring Boot `Admin`


简介

  • Spring Boot ​​Admin​​ 用于监控基于 Spring Boot 的应用,它是在 Spring Boot Actuator 的基础上提供简洁的可视化 WEB UI。
  • Spring Boot ​​Admin​​ 提供了很多功能,如显示 name、id 和 version,显示在线状态,Loggers 的日志级别管理,Threads 线程管理,Environment 管理等。
  • 在 Spring Boot 项目中,Spring Boot ​​Admin​​ 作为 Server 端,其他的要被监控的应用作为 Client 端

Server服务端

版本介绍:本次使用的是Spring Cloud ​​Greenwich.SR6​​​ 版本、Spring Boot ​​2.1.5.RELEASE​​版本

// POM文件
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
//异常:java.lang.IllegalStateException: Calling [asyncError()] is not valid for a request with Async state
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<!--添加Jetty-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>
<!--监控Server端 + UI-->
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-server</artifactId>
<version>2.1.3</version>
</dependency>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-server-ui</artifactId>
<version>2.1.3</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
//yml文件配置
server:
port: 8101
spring:
application:
name: admin-server
eureka:
instance:
prefer-ip-address: true
instance-id: admin-server-8101
client:
service-url:
defaultZone: http://localhost:8761/eureka/
// java 文件,添加注解,这是集成Eureka,将服务注册到Eureka中
@SpringBootApplication
@EnableAdminServer
@EnableEurekaClient
@EnableDiscoveryClient

Client客户端

// POM 文件修改
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<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>
<version>2.1.3</version>
</dependency>
//yml文件修改,这里没有将客户端注册到Eureka中。实际项目中需要将服务提供者注册进去,进行监控。我的另一个微服务都注册到了Eureka中。
server:
port: 9101
spring:
application:
name: admin-client
boot:
admin:
client:
url: http://localhost:8101
management:
endpoints:
web:
exposure:
include: '*'
endpoint:
health:
show-details: always
logging:
file: /admin-client.log

图片演示

SpringCloud 第十章:Spring Cloud Greenwich 版本集成Spring Boot `Admin`_Springbootadmin


SpringCloud 第十章:Spring Cloud Greenwich 版本集成Spring Boot `Admin`_SpringCloud_02


SpringCloud 第十章:Spring Cloud Greenwich 版本集成Spring Boot `Admin`_SpringCloud_02


代码地址,链接如下

欢迎点赞、关注!

SpringCloud Dalston版本代码开源地址:​​代码地址​​

SpringCloud Hoxton版本代码开源地址:​​代码地址​​


举报

相关推荐

0 条评论