如何在Spring Cloud中创建自定义Zuul过滤器 [英] How do you create custom zuul filters in spring cloud

查看:124
本文介绍了如何在Spring Cloud中创建自定义Zuul过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为我正在编写的Spring Cloud微服务编写一些自己的自定义zuul过滤器.编写完过滤器后,如何集成它,以便底层的netflix zuul框架可以利用它.

I want to write some of my own custom zuul filters for a spring cloud microservice i am writing. Once i have the filter written how do I integrate it so the underlying netflix zuul framework can take advantage of it.

推荐答案

创建扩展ZuulFilter@Bean.请参阅Java配置示例

Create a @Bean that extends ZuulFilter. See java configuration examples here. As long as the bean is in the same context as the @EnableZuulProxy app, it will automatically get picked up.

@Bean
public MyFilter myFilter() {
    return new MyFilter();
}

请参阅过滤器示例过滤器分为三种:前置过滤器,路由过滤器和邮政过滤器,并且每组过滤器均按该顺序执行(即,所有过滤器的第一过滤器,路由第二的过滤器和邮政过滤器的第三过滤器).

There are three types of filters: pre, route and post and each set of filters is executed in that order (ie all pre's first, routes 2nd and post's 3rd).

这篇关于如何在Spring Cloud中创建自定义Zuul过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆