說明:此搭建過程,全程依賴註冊中心
- 創建註冊中心,以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,則不需要引用該兩項配置,就能正常訪問,如配置中心服務端,則不需要引入該配置