说明:此搭建过程,全程依赖注册中心
- 创建注册中心,以eureka为例这里不详细说明
- 创建SpringBoot Admin 服务端
2.1,创建SpringBoot 项目,引入以下包
<!-- 注册中心 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<!-- Springboot Admin 服务端 -->
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-server</artifactId>
</dependency>
<!-- web 引用 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- 验证引用 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<!--暴露各种指标-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
2.2, ApplicationMain中修饰
2.3, 配置文件
# 注册中心
eureka:
client:
service-url:
defaultZone: http://localhost:8761/eureka/
# 服务名称,验证说明, SpringBoot Admin 用户
spring:
application:
name: monitor-admin
security:
basic:
enabled: false
user:
password: 123456
name: admin
# Admin 管理配置
management:
endpoints:
web:
exposure:
include: '*'
endpoint:
health:
show-details: always
3.客户端使用
3.1,客户端必须注册到注册中心才能使用
3.2,Pom 引用
<!-- web 引用 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- 暴露指标 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
注意:如若服务不为web,则不需要引用该两项配置,就能正常访问,如配置中心服务端,则不需要引入该配置