一、SpringBootAdmin服务端
1. 添加必要依赖
<!--Spring Boot Starter-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<!--Spring Boot Admin Server UI-->
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-server-ui</artifactId>
</dependency>
<!--Spring Boot Admin Server-->
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-server</artifactId>
</dependency>
2. 添加必要配置
在这个配置文件中server.port监听的端口就是一会要访问的端口
server:
port: 8000
spring:
application:
name: monitor-server
# 开放健康检查接口
management:
endpoints:
web:
exposure:
include: "*"
endpoint:
health:
show-details: ALWAYS
3. 启动类添加必要的注解 @EnableAdminServer
@EnableAdminServer
@SpringBootApplication
public class MonitorApplication {
public static void main(String[] args) {
SpringApplication.run(MonitorApplication.class, args);
}
}
4. 启动服务端,访问 localhost:8000
即可看到当前在线的服务。
二、SpringBootAdmin客户端
1. 添加必要依赖
<!--SpringBootAdmin -->
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-client</artifactId>
<version>2.3.1</version>
</dependency>
2. 添加必要配置信息
server:
port: 8001 # 客户端将要监听的端口
spring:
application:
name: secret-app
boot:
admin:
client:
url: "http://localhost:8000" # 服务端监听的端口
management:
endpoints:
web:
exposure:
include: "*"
# 开放健康检查接口
endpoint:
health:
show-details: ALWAYS
在保证服务端已经启动的前提下,启动客户端,等待几秒后,可以在ui界面中看到客户端服务信息