I'm using spring cloud gateway filter, and want to filter request by GatewayFilterFactory
,
but order not working with @Order
annotation
I tried to swap the order of filters, but not working.
@Slf4j
@Order(1)
@Component
public class AccessFilter implements GatewayFilterFactory<AccessFilter.Config> {
@Override
public GatewayFilter apply(AccessFilter.Config config) {
return (exchange, chain) -> {
log.info("in AccessFilter second");
// do something
}
}
}
@Order(-1)
@Slf4j
@Component
public class AddTraceIdGlobalFilter implements GlobalFilter {
@Override
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
log.info("in globalfilter first");
// do something
}
}
My yaml file:
spring:
cloud:
gateway:
routes:
- id: user_1
uri: http://user:8080
predicates:
- Path=/v1/user/info
filters:
- AccessFilter
I expect the output:
in globalfilter first
in AccessFilter second
but the actual output:
in AccessFilter second
in globalfilter first