Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在SpringCloudGateway中为发现定位器编写复杂谓词?_Spring_Spring Cloud_Spring Cloud Gateway - Fatal编程技术网

如何在SpringCloudGateway中为发现定位器编写复杂谓词?

如何在SpringCloudGateway中为发现定位器编写复杂谓词?,spring,spring-cloud,spring-cloud-gateway,Spring,Spring Cloud,Spring Cloud Gateway,我想自定义发现定位器的行为。例如,在我的案例中,有一个是从网关\u主机/禁止路由到名为禁止ui的服务。为此,我使用以下配置: spring: cloud: gateway: discovery: locator: enabled: true lower-case-service-id: true filters: PreserveHostHeader include-expre

我想自定义发现定位器的行为。例如,在我的案例中,有一个是从
网关\u主机/禁止
路由到名为
禁止ui
的服务。为此,我使用以下配置:

spring:
  cloud:
    gateway:
      discovery:
        locator:
          enabled: true
          lower-case-service-id: true
          filters: PreserveHostHeader
          include-expression: serviceId.endsWith('-UI')
          predicates: Path='/'+serviceId.substring(0,serviceId.indexOf('-UI'))+'/**'
然后错误:

Failed to bind properties under 'spring.cloud.gateway.discovery.locator.predicates' to java.util.List<org.springframework.cloud.gateway.handler.predicate.PredicateDefinition>:

Reason: failed to convert java.lang.String to org.springframework.cloud.gateway.handler.predicate.PredicateDefinition
无法将“spring.cloud.gateway.discovery.locator.predicates”下的属性绑定到java.util.List:
原因:未能将java.lang.String转换为org.springframework.cloud.gateway.handler.predicate.PredicateDefinition
我认为这个错误是由于传递给
substring
方法的两个参数引起的。若我将方法调用更改为
子字符串(0)
,则应用程序将成功启动,但这样的配置对我来说毫无意义:
谓词:Path='/'+serviceId.substring(0)+'/**'
属性
spring.cloud.gateway.discoverycatorproperties
引用谓词定义列表,请参见
org.springframework.cloud.gateway.discoverycatorproperties
。您指定的内容已转换为
字符串
,因此无法转换为所需类型

您可以尝试按如下方式指定谓词:

spring:
  cloud:
    gateway:
      discovery:
        locator:
          predicates: 
          - name: Path
            args:
              pattern: '/'+serviceId.substring(0,serviceId.indexOf('-UI'))+'/**'