昨天只是极简入门,关于网关是怎么感知到我们的应用的,相信小伙伴们一定有疑问,今天先来看下 HTTP 用户如何接入 Soul,以及接入的流程是怎样的。
这是官网对于 HTTP 用户的文档,https://dromara.org/zh-cn/docs/soul/user-http.html。
官网文档明确指出,Soul 网关使用 divide 插件来处理http请求,我们在 soul-admin 页面中看到,第一个就是 divide 插件,而且是默认开启的。
Http请求接入网关,分2种情况,1种是 springMvc 体系用户,1种是非 springMvc 体系。
对于非 springMvc 体系接入,是通过 soul-admin 的页面操作来完成的,这个流程我们后边再分析。
对于 springMvc 体系用户,通过注解和配置,就自动同步到 divide 插件下的选择器规则列表,我们今天就来一探究竟。
1.配置文件
无论是 Spring Boot 用户,还是 Spring MVC 用户,都需要一段配置(以 Spring Boot 为例)
soul:
http:
adminUrl: http://localhost:9095
port: 你本项目的启动端口
contextPath: /http
appName: http
full: false
# adminUrl: 为你启动的soul-admin 项目的ip + 端口,注意要加http://
# port: 你本项目的启动端口
# contextPath: 为你的这个mvc项目在soul网关的路由前缀,这个你应该懂意思把? 比如/order ,/product 等等,网关会根据你的这个前缀来进行路由.
# appName:你的应用名称,不配置的话,会默认取 `spring.application.name` 的值
# full: 设置true 代表代理你的整个服务,false表示代理你其中某几个controller
回到我们的测试项目 soul-examples-http 中,查看其配置文件 application.yml
soul:
http:
adminUrl: http://localhost:9095
port: 8188
contextPath: /http
appName: http
full: false
在 http 层级下任一属性上,Ctrl+B,自动跳转到 Bean 类 SoulSpringMvcConfig。
@Data
public class SoulSpringMvcConfig {
private String adminUrl;
private String contextPath;
private String appName;
/**
* Set true means providing proxy for your entire service, or only a few controller.
*/
private boolean full;
private String host;
private Integer port;
}
不得不佩服 IDEA 的开发团队,好多功能简直太强大太方便了,在 SoulSpringMvcConfig 类左边,直接导航到 Spring Bean 的定义。

直接就跳转到这里了,SoulSpringMvcClie

本文详细介绍了SpringMVC应用如何接入Soul网关的过程,包括配置文件设置、@SoulSpringMvcClient注解的使用,以及自动注册到SoulAdmin的流程。核心逻辑在于通过配置信息和注解内容,结合SpringBootStarter,调用soul-admin接口完成接口注册。
最低0.47元/天 解锁文章
469

被折叠的 条评论
为什么被折叠?



