com.ruoyi.gateway
今天简单看看若依的gateway的配置模块干了啥
最近面试很多外包公司,都对低代码平台有点要求,这些代码虽说用起来不费劲,但是其中还是有很多细节能让我学习学习的。(微服务版,上次搞jeecgboot的笔试题差点把我人带走了)
简单的看一眼,总共分为4个文件夹和1个启动类。
0. pom文件
<parent>
<groupId>com.ruoyi</groupId>
<artifactId>ruoyi</artifactId>
<version>3.6.4</version>
</parent>
dependencies
spring-cloud-starter-gateway
spring-cloud-starter-alibaba-nacos-discovery
spring-cloud-starter-alibaba-nacos-config
spring-cloud-starter-alibaba-sentinel
spring-cloud-alibaba-sentinel-gateway
sentinel-datasource-nacos
spring-boot-starter-actuator
spring-cloud-loadbalancer
kaptcha
ruoyi-common-redis
springdoc-openapi-webflux-ui
1. 先看一眼启动类
emm,没什么特别就加了一个注解,用来剔除数据库的自动配置的。
@SpringBootApplication(exclude = {
DataSourceAutoConfiguration.class })
2. 从头开始看,第一个是config
- config
- properties(首先也是一个目录,里面写了一些属性)
- CaptchaConfig:验证码的配置
- GatewayConfig:网关限流配置
- KaptchaTextCreator:验证码文本生成器(这里是no usages的)
- RouterFunctionConfiguration:路由配置
- SpringDocConfig:文档的配置类
CaptchaConfig
这里用的是google的kaptcha的包,里面注册了两个bean,一个是default的验证码bean,一个是数字的bean。
GatewayConfig:这里主要是注册了一个自定义的限流处理
@Configuration
public class GatewayConfig{
@Bean
@Order(Ordered.HIGHEST_PRECEDENCE)
// 这里的SentinelFallbackHandler自定义的限流处理,跳转过去看看
public SentinelFallbackHandler sentinelGatewayExceptionHandler(){
return new SentinelFallbackHandler();
}
}