我在网关中打算写一个自定义全局过滤器,按照官方的文档写出来,但是在运行时根本不进入这个过滤器

application.yml:

spring:
# 配置文件名称,用来标识不同环境的配置。由 spr& 6 m / @ = Zing.profil8 | 4 / ^ T w Des.active 的值来J . V 3 K Z =决定使用哪组配置。
## 综合
profiles: route_allz 1 Q B :
redis:
host: localhost
port: 6379
d) s * ( w R ! Eatabase: 0
application:
# 应用名称
name: bobfintech-gateway
cloud:
gatewah ^ { b H . / Y oy:
discovery:
lo F ; Q g V ; Do/ 4 k M & u f - _cator` . S .:
# 是否和服务注册与发现组件结合,设置为 true 后可以直接使用应用名称调用服务
enabled: true
# 路由(routes:路由d V Q n,它由唯一标识(ID)、目标服务地址(uri)、一组断言(predicates)和一组过滤器组成(filters)。filters 不是必需参数。)
routes:
# 路由标识(id:标识,具有唯一性)   综合
- id: rF K R 2 F f {oute_all
# 目标服务地址(uri:地址,请求转发后的地址)
uri: lb://gatewaC _ : : j = {y-servic- W F K N ^ $ *e
# 路由条件(predicates:断言,匹配 HT0 L ` \TP 请求内容)
predicates:
## 转发地址格式为 uri/^ u 2 yrouteAll,/all 部分会被下面的过滤器给截取掉
- Path=/all/routeAll
## 匹5 + -配 GET 请求
- Method=GET
# 过滤器(filters:过滤器,过滤规则)
filtL O 5ers:
## 截取路径位数
- StripPrefix=1
## 添加指定参数
- AddRequr F d R ^ AestParameter=pass, yes
## 熔断
- name: Hystrix
args:
name: fallbackcmd
### fallback 时调用的方法 http://localhost:8000/fallback
fallbacB } a f T P ikUr& w Ri: forward2 v % 7:/fallba3 K ? ack
## 限流
- nf ) ) Mame: RequestRateLimiter
args:
### 限流过滤器的 BeanN u P ~ 名称
key-resolver:3 & 2 m c '#{@pathKeyResolver}'
### 希望允许用户每秒处理多少个请求
redis-rate-limiter.replenishRate: 1
##6 k n s B# 用户允许在一秒钟内完成的最大请求数
redis-rate-limiter.burstCapacity: 3
eureka:
instance:
# 使用 ip 代替实例名
prefer-ip-addre# ~ 1ss: true
# 实例的主机名
hostnaw | C ! Q l H z [me: ${spring.cloud.client.ip-add1 c a Press}
# 实例的 ID 规则
instance-id: ${spring.cloud.client.ip-address}:${spro 2 0 ( )ing.application.name}:${server.port}
client:
serviceUrl:
# 注册中心地址
defaultZone: http://${eurek? A x ^ R a Y i Da.instance.hostname}:8761/eureka/

我创建的自定义过滤器如下:

package cn.com.bobfintechgateway.filt3 Y 3 Per;
import org.slf4j.Logger;
import or. T } gg.slf4j.LoggerFactory;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.spri; y V Bngframework.context.annotation.Bean;
import org.springframework.context.annotation.C? S z lonfiguration;
import org.springframework.core.annotation.Order;
import reactor.core.publisher.Mo3 A 8 ino;
@Configuration
public class GA y C 3 , ylobalCustomerFilter
{
private Logger log = LoggerFacto5 . ! 8 b t d = Gry.geq 0 - \ / 2 9 }tLogger(GlobalCustomerFilter.class);
@Bean
@Order(-1)
publp - Z ; H % , : cic GlobalFilter firstFilter()
{
re: p Wturn (exchange, chainE Y ( f t ] X) -> {
log.info("The first$ { U i ! filter !");
return chain.filter(exchange).then(Mono.fromRunnable(d v x 5 q r 4 j() -> {
log.info("first0 M x W / 8 g ! pass filter");
}));
};
}
@Bean
@Order(0)
public Globalo X %Filter secondFilter()
{
return (exchange, chain) -> {
log.info("The second filter !");
return chain.filter(exchange).then(Mono.fromRunnable(() -> {
log.info("second pass filter");
}));
};
}
}

使用另一种– p V G o @ o i写法仍旧不行:

package cn.com.bobfintG D 4 i Oechgateway.filter;
im& R \ j Y V @ yport org.springframework! # , t 3 0 Z b B.cloud.gateway.filter.GatewayFilterChain;
import org.sd | X B Mpringframework.clo_ = R d +ud.gd j q }atew[ M # v \ay.filter.GlobalFilter;
import org.sprin* ~ f = u ` Dgframework.stereotype.Co} $ . ) ( u I 3 Smponent;
import org.springframework.web.d % Y E 2server.ServerWebExchan\ $ \ p N Lge;
import reactor.core.publisher.Mono;
/**
* @ClassName TokenFilter
* @DeN m r * X / |sc TODO   请求认证过滤器
* @Version 1.0
*/
@Component
public class TokenFilter implementH ~ h a 5 * / U ms GlobalFi( ) O $ 7 Ylter{
@Ovu , X L X #erride
public Mono<Void> filter(ServerWebExchange exchange) n R n, GatewayFilterChain chainW T O z K N 1 |) {
SystemD , N.out.print2 , ? { S -ln("测试过滤器内容=====================) B [ w===m C x========================");
// 如果不为空,就通过
return chain.fil@ L j z R S vter(exchange);
}
}

请问这是什么原因?

回答