一、简介
Spring Boot Admin 客户端的搭建是很简单的。通过 maven 引入 spring-boot-admin-starter-client,maven就会将必要的jar包引入到项目中,其中就包括actuator。在通过简单的配置就可以在Spring Boot Admin 服务端监控微服务应用即Spring Boot应用。
二、实战
1、项目结构
2、microservice-provider -> pom.xml
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <parent> <artifactId>microservice-minitor</artifactId> <groupId>com.microservice</groupId> <version>1.0-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>microservice-provider</artifactId> <dependencies> <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.2.0</version> </dependency> </dependencies> </project>
3、microservice-provider -> application.yml
spring:
application:
name: microservice-provider
boot:
admin:
client:
url: http://localhost:8888
server:
port: 8101
management:
endpoints:
web:
exposure:
include: '*'
endpoint:
health:
show-details: ALWAYS
至此客户端配置就完成了。其实Consumer和Provider的配置类似
三、运行测试
1、启动 microservice-monitor-server
2、启动microservice-provider,可以多启动几个实例。
3、启动microservice-consumer
打开浏览器:http://localhost:8888/wallboard
并查看其中一个实例,看看都有啥:
运行成功,效果完美!