对于最新的稳定版本,请使用 Spring Framework 6.2.0spring-doc.cadn.net.cn

上下文

属性提供了一种将信息传递给过滤器的便捷方法 chain,但它们只影响当前请求。如果要传递 传播到嵌套的其他请求,例如通过flatMap,或在 例如,通过concatMap,则需要使用 ReactorContext.spring-doc.cadn.net.cn

反应堆Context需要在响应式链的末尾填充,以便 应用于所有作。例如:spring-doc.cadn.net.cn

WebClient client = WebClient.builder()
		.filter((request, next) ->
				Mono.deferContextual(contextView -> {
					String value = contextView.get("foo");
					// ...
				}))
		.build();

client.get().uri("https://example.org/")
		.retrieve()
		.bodyToMono(String.class)
		.flatMap(body -> {
				// perform nested request (context propagates automatically)...
		})
		.contextWrite(context -> context.put("foo", ...));