微服务自动注册到ShenYu网关配置详解
一、配置逐行详解
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。 - 你需要