How do you create custom zuul filters in spring cloud

陌路散爱 提交于 2019-11-26 17:05:40

问题


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.


回答1:


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();
}

See examples of filters here.

public class MyFilter extends ZuulFilter {
    //...
}

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).



来源:https://stackoverflow.com/questions/28467756/how-do-you-create-custom-zuul-filters-in-spring-cloud

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!