自定义局部过滤器
自定义局部过滤器;继承AbstractGatewayFilterFactory
server:
port: 10010
spring:
application:
name: api-gateway
cloud:
gateway:
routes:
# 路由id,可以任意
- id: user-service-route
# 代理的服务地址
#uri: http://127.0.0.1:9090
# lb表示从eureka中获取具体服务 ;lb 之后编写的服务名必须要在eureka中注册才能使用
uri: lb://UserService
# 路由断言: 可以匹配映射路径
predicates:
#- Path=/UserController/**
#- Path=/**
- Path=/api/UserController/**
filters:
#1表示过滤1个路径,2表示两个路径,以此类推
- StripPrefix=1
- #自定义过滤器 : 名称 + GatewayFilterFactory就是类名称了
- MyParam=name
# 默认过滤器,对所有的路由都生效(全局)
default-filters:
- AddResponseHeader=X-Response-Foo,Bar
- AddResponseHeader=x-myname,itcast
eureka:
client:
service-url:
defaultZone: http://127.0.0.1:10086/eureka
instance:
prefer-ip-address: true
自定义过滤器
MyParamGatewayFilterFactory --》yml中的MyParam
package li.chen.com.filter;
import org.springframework.cloud.gateway.filter.GatewayFilter;
import org.springframework.cloud