首页 » 文章 » spring cloud gateway 全局filter,GlobalFilter

spring cloud gateway中有gateway filter 和global filter,前者是针对路由规则配置到某个路由规则上,后者是全局的。定义一个全局filter的方法如下

@Component
public class GlobalFilterConfig {
    @Bean
    @Order(-1)
    public GlobalFilter a() {
        return (exchange, chain) -> {
            System.out.print("first pre filter");
            return chain.filter(exchange).then(Mono.fromRunnable(() -> {
                System.out.print("third post filter");
            }));
        };
    }
}

添加新评论