spring-cloud / spring-cloud-gateway

An API Gateway built on Spring Framework and Spring Boot providing routing and more.
http://cloud.spring.io
Apache License 2.0
4.5k stars 3.31k forks source link

Add option to ignore `IllegalArgumentException` if discovery locator enabled #2952

Open caixunshi opened 1 year ago

caixunshi commented 1 year ago

Is your feature request related to a problem? Please describe. If an illegal appname is registered on Eureka, such as "lb:// ", it will cause the service to fail to start and throw "Illegal character in authority at index 5: lb://"

Describe the solution you'd like filter out illegal appnames during startup

Describe alternatives you've considered When registering a service for the eureka client, if it is an illegal uri, block the registration of the service and throw an exception

Additional context Add any other context or screenshots about the feature request here.

caixunshi commented 1 year ago

mmexport1683858712876

haitaoss commented 1 year ago

This cannot be considered a bug, access addresses cannot contain spaces. Alternatively, you can write SpEL to remove spaces, as shown in the example code:

spring:
  cloud:
    gateway:
      discovery:
        locator:
          enabled: true
          urlExpression: "'lb://'+serviceId"
          predicates:
            - name: Path
              args:
                patterns: "'/'+serviceId+'/**'.replaceAll(' ','')"
caixunshi commented 1 year ago

This is not an interface path, it is a service path. Registering a service name with eureka starts with an empty string, causing all SpringCloud gateway based services to start with an error