3

我尝试使用上下文在 SpringCloud Gateway 的过滤器中设置 Reactor3 的一些值,但在控制器中,我无法获取上下文中的值。

实际上,我是 Reactor3 的新手。所以请给我一些提示或帮助,非常感谢!

//my GatewayFilter
@Override
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {

    return chain.filter(exchange)
             .subscriberContext(ctx -> ctx.put("key", "hello gate"));
}

//my Controller
@ResponseBody
@RequestMapping("/test")
public Mono<String> test() {

     return Mono.subscriberContext()
            .map(ctx -> ctx.get("key"));
}

当我尝试获取 Context 的值时,它会抛出异常“上下文为空”

4

0 回答 0