如何在zuul网关应用程序(spring boot)中创建多个(pre / post)过滤器。
例:
/endpoint1 - should call (Filter 1)
/endpoint2 - should be served by (Filter2)
目前我了解每个请求来到网关,将由一个过滤器(前,路由,帖子)处理
您可以为一个端点或多个端点使用多个过滤器。
如果要为某些端点而不是其他端点应用过滤器,可以使用此过滤器的shouldFilter()
方法(例如预过滤器)来定义用例。就像是 :
@Override
public boolean shouldFilter() {
String endpointToFilter = RequestContext.getCurrentContext().getRequest().getRequestURI();
endpointToFilter = endpointToFilter.substring(0, endpointToFilter.indexOf("/", 1));
boolean shouldFilter = "endpoint1".equals(endpointToFilter);
return shouldFilter;
}