1.创建Springboot Admin Server
正常创建完后去配置文件查看依赖项是否存在,没有的手工添加
<!--admin server服务-->
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-server</artifactId>
</dependency>
2.配置相关文件application.propertier
#服务名称
spring.application.name=Spring Boot Server
#服务端口
server.port=9001
3.入口类添加注解
@EnableAdminServer
4.启动查看监控页面(2.X的UI界面是用VUE写的,美的很)
因为没有客户端(服务),所以上面显示是0个应用。
5.创建Springboot Admin client
正常情况下,pom里的依赖项应该有以下内容:
<dependencies>
<!--监控和管理Spring Boot应用-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!--web页面依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--admin客户端-->
<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>
</dependencies>
6.配置客户端application.properties
#应用端口
server.port=9101
#应用名称
spring.application.name=Spring Boot Client
#admin服务地址
spring.boot.admin.client.url=http://localhost:9001
#admin暴露的接口规则,*表示所有
management.endpoints.web.exposure.include=*
7.运行应用,查看效果
- 客户端应用启动时有消息提醒
- 监控中心页面数据发生了变化。
- 应用停止时提示
- 应用停止后监控中心数据变化