Search code examples
spring-cloud-gateway

Reuse filters in all routes in Spring Cloud Gateway


In my configuration I have the following filters defined in all routes:

          filters:
            - name: CacheRequestBody
              args:
                bodyClass: java.lang.String
            - StripPrefix=1

I wonder if it's possible to make them "global", so I won't need to define them in each route?


Solution

  • You can make use of spring.cloud.gateway.default-filters to apply filters to all routes:

    spring:
      cloud:
        gateway:
          default-filters:
            - name: CacheRequestBody
              args:
                bodyClass: java.lang.String
            - StripPrefix=1
    
    

    Reference documentation