From c1250b1898c21bd09449dd1f7dc6f783d7cc7d05 Mon Sep 17 00:00:00 2001 From: rstoyanchev Date: Fri, 21 Jun 2024 10:55:14 +0100 Subject: [PATCH] Replace use of deprecated ContextSnapshot methods See gh-32813 --- .../mvc/method/annotation/ReactiveTypeHandler.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ReactiveTypeHandler.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ReactiveTypeHandler.java index 4d22dd957d..90afb4f6c1 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ReactiveTypeHandler.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ReactiveTypeHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,6 +26,7 @@ import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicReference; import io.micrometer.context.ContextSnapshot; +import io.micrometer.context.ContextSnapshotFactory; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.reactivestreams.Publisher; @@ -517,14 +518,16 @@ class ReactiveTypeHandler { private static class ContextSnapshotHelper { - @SuppressWarnings("deprecation") + private static final ContextSnapshotFactory factory = ContextSnapshotFactory.builder().build(); + + @SuppressWarnings("ReactiveStreamsUnusedPublisher") public static Object writeReactorContext(Object returnValue) { if (Mono.class.isAssignableFrom(returnValue.getClass())) { - ContextSnapshot snapshot = ContextSnapshot.captureAll(); + ContextSnapshot snapshot = factory.captureAll(); return ((Mono) returnValue).contextWrite(snapshot::updateContext); } else if (Flux.class.isAssignableFrom(returnValue.getClass())) { - ContextSnapshot snapshot = ContextSnapshot.captureAll(); + ContextSnapshot snapshot = factory.captureAll(); return ((Flux) returnValue).contextWrite(snapshot::updateContext); } else {