一、配置逐行詳解
shenyu:register:registerType: http # 注冊中心類型:使用 HTTP 協議進行注冊serverLists: ${shenyu-register-serverLists} # ShenYu Admin 的地址列表props:username: ${shenyu-register-props-username} # 注冊認證用戶名password: ${shenyu-register-props-password} # 注冊認證密碼client:http:props:contextPath: ${server.servlet.context-path} # 最重要的配置:本服務的上下文路徑appName: ${spring.application.name} # 本服務的應用名isFull: true # 注冊模式:全量注冊
這段配置是 ShenYu 客戶端(你的業務微服務)的配置,它的核心目的是:讓你的微服務能夠自動注冊到 ShenYu 網關,而無需在網關管理界面上手動配置路由規則。
二、在 Nacos 中配置它的核心作用
在 Nacos 中配置這段信息(通常是作為一個 dataId
,例如 shenyu-client-http.yaml
,被你的微服務引用),是為了實現 “服務自動發現” 和 “路由自動配置”。
沒有它之前(手動模式):
- 你的微服務
user-service
啟動,端口 8080。 - 你需要