後端筆記04-AdminClient
阿新 • • 發佈:2020-12-09
SpringBoot4-adminclient
本專案演示如何整合使用Spring Boot Admin,並將自己的執行狀態交給Spring Boot Admin進行展示,和adminclient配套使用的是adminserver
這裡先給出adminclient的程式碼,在adminserver詳細描寫使用
pom.xml
<dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>com.pig4cloud</groupId> <artifactId>spring-boot-admin-starter-client</artifactId> <version>0.1.2</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies>
這裡匯入的依賴包是阿里雲的映象,按照demo的依賴執行時,出現了錯誤,在這裡更正為阿里雲的映象版本後正常
<mirror>
<id>aliyunmaven</id>
<mirrorOf>*</mirrorOf>
<name>阿里雲公共倉庫</name>
<url>https://maven.aliyun.com/repository/public</url>
</mirror>
application.yml
server: port: 8044 servlet: context-path: /study spring: application: # Spring Boot Admin展示的客戶端專案名,不設定,會使用自動生成的隨機id name: spring-boot-demo-admin-client boot: admin: client: # Spring Boot Admin 服務端地址 url: "http://localhost:8000/" instance: metadata: # 客戶端端點資訊的安全認證資訊 user.name: ${spring.security.user.name} user.password: ${spring.security.user.password} security: user: name: admin password: admin management: endpoint: health: # 端點健康情況,預設值"never",設定為"always"可以顯示硬碟使用情況和執行緒情況 show-details: always endpoints: web: exposure: # 設定端點暴露的哪些內容,預設["health","info"],設定"*"代表暴露所有可訪問的端點 include: "*"
application.yml中是對Spring Boot Admin的一些配置,其中Spring Boot Admin的服務端地址必須和服務端專案對應,不然無法正確註冊服務
IndexController.java
@RestController
public class IndexController {
@GetMapping(value = {"", "/"})
public String index() {
return "this is a Spring Boot Admin Client.";
}
}
搬運自我的 Git:https://github.com/miles-rush/StudyNote
SpringBoot-Demo:https://github.com/xkcoding/spring-boot-demo 的學習筆記