How do you create custom zuul filters in spring cloud

前端 未结 1 1082
日久生厌
日久生厌 2020-12-03 19:08

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 netf

相关标签:
1条回答
  • 2020-12-03 19:27

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

    0 讨论(0)
提交回复
热议问题