Parcourir la source

feat:路径断言工厂,通过配置类配置

yang yi il y a 1 an
Parent
commit
86fe021030

+ 1 - 1
member-service-consumer/src/main/java/anyi/space/memberConsumer/config/GatewayConfig.java

@@ -16,7 +16,7 @@ import org.springframework.http.HttpMethod;
  */
 @Configuration
 public class GatewayConfig {
-    //@Bean
+    @Bean
     public RouteLocator myRouteLocator01(RouteLocatorBuilder builder){
         //根据配置文件改写为配置类的形式
         RouteLocatorBuilder.Builder routes = builder.routes();

+ 26 - 26
member-service-consumer/src/main/resources/application.yaml

@@ -14,32 +14,32 @@ spring:
       #配置路由,可以配置多组
       routes:
         #配置路由的id,需要全局唯一,查询数据使用该路由
-        - id: member10001
-          #路由转发的URI,最终转发的URL = URI + PATH
-          #uri: http://localhost:10001
-          #使用负载均衡
-          uri: lb://member-service-provider
-          #配置路由的断言,满足条件时才进行路由
-          predicates:
-            #路径断言,参数为正则表达式字符串列表,多个则使用逗号分割,正则表达式中使用具名捕获分组,则捕获分组的值可以在过滤器中使用
-            - Path=/member-gateway/member
-            #方法断言,参数为请求方法的字符串列表,多个则使用逗号分割
-            - Method=GET
-            #后置时间断言,时间格式为ZonedDateTime
-            #- After=2025-09-10T19:01:03.749+08:00[Asia/Shanghai]
-            #前置时间断言,时间格式为ZonedDateTime
-            #- Before=2025-09-11T19:01:03.749+08:00[Asia/Shanghai]
-            #时间区间断言,两个参数,只有在时间区间的的请求才能通过断言,时间格式为ZonedDateTime
-            #- Between=2025-09-10T19:01:03.749+08:00[Asia/Shanghai],2025-09-11T19:01:03.749+08:00[Asia/Shanghai]
-            #cooike断言,格式为: "name,value",name为cookie的名称,value为cookie的值,value为正则表达式
-            #- Cookie=name,value
-            #Header断言,第一个参数为请求头的名称,第二个参数为请求头的值(正则表达式),格式为:name,value
-            #- Header=name,value
-            #Host断言,参数为Ant格式的符合Host格式的字符串列表,多个则使用逗号分割
-            #- Host=localhost,127.0.0.1,**.space
-          filters:
-            #重写路径,将请求路径中的member-gateway替换为member-provider,使用到正则表达式的命名捕获分组,语法格式:(?<捕获分组名称>pattern),引用捕获分组:$\{捕获分组名称}
-            - RewritePath=/member-gateway/(?<segment>.*), /member-provider/$\{segment}
+#        - id: member10001
+#          #路由转发的URI,最终转发的URL = URI + PATH
+#          #uri: http://localhost:10001
+#          #使用负载均衡
+#          uri: lb://member-service-provider
+#          #配置路由的断言,满足条件时才进行路由
+#          predicates:
+#            #路径断言,参数为正则表达式字符串列表,多个则使用逗号分割,正则表达式中使用具名捕获分组,则捕获分组的值可以在过滤器中使用
+#            - Path=/member-gateway/member
+#            #方法断言,参数为请求方法的字符串列表,多个则使用逗号分割
+#            - Method=GET
+#            #后置时间断言,时间格式为ZonedDateTime
+#            #- After=2025-09-10T19:01:03.749+08:00[Asia/Shanghai]
+#            #前置时间断言,时间格式为ZonedDateTime
+#            #- Before=2025-09-11T19:01:03.749+08:00[Asia/Shanghai]
+#            #时间区间断言,两个参数,只有在时间区间的的请求才能通过断言,时间格式为ZonedDateTime
+#            #- Between=2025-09-10T19:01:03.749+08:00[Asia/Shanghai],2025-09-11T19:01:03.749+08:00[Asia/Shanghai]
+#            #cooike断言,格式为: "name,value",name为cookie的名称,value为cookie的值,value为正则表达式
+#            #- Cookie=name,value
+#            #Header断言,第一个参数为请求头的名称,第二个参数为请求头的值(正则表达式),格式为:name,value
+#            #- Header=name,value
+#            #Host断言,参数为Ant格式的符合Host格式的字符串列表,多个则使用逗号分割
+#            #- Host=localhost,127.0.0.1,**.space
+#          filters:
+#            #重写路径,将请求路径中的member-gateway替换为member-provider,使用到正则表达式的命名捕获分组,语法格式:(?<捕获分组名称>pattern),引用捕获分组:$\{捕获分组名称}
+#            - RewritePath=/member-gateway/(?<segment>.*), /member-provider/$\{segment}
         #第二组路由,新增数据使用该路由
         - id: member10002
           uri: http://localhost:10002