diff --git a/spring-core/src/main/java/org/springframework/core/ReactiveAdapterRegistry.java b/spring-core/src/main/java/org/springframework/core/ReactiveAdapterRegistry.java
index 0b816fd9371..5cf10f1618f 100644
--- a/spring-core/src/main/java/org/springframework/core/ReactiveAdapterRegistry.java
+++ b/spring-core/src/main/java/org/springframework/core/ReactiveAdapterRegistry.java
@@ -36,12 +36,12 @@ import rx.RxReactiveStreams;
import org.springframework.util.ClassUtils;
/**
- * A registry of adapters to adapt to {@link Flux} and {@link Mono}.
+ * A registry of adapters to adapt a Reactive Streams {@link Publisher} to/from
+ * various async/reactive types such as {@code CompletableFuture}, RxJava
+ * {@code Observable}, and others.
*
*
By default, depending on classpath availability, adapters are registered
- * for RxJava 1, RxJava 2 types, and {@link CompletableFuture}. In addition the
- * registry contains adapters for Reactor's own Flux and Mono types (no-op)
- * along with adaption for any other Reactive Streams {@link Publisher}.
+ * for Reactor, RxJava 1, RxJava 2 types, and {@link CompletableFuture}.
*
* @author Rossen Stoyanchev
* @author Sebastien Deleuze
@@ -49,6 +49,9 @@ import org.springframework.util.ClassUtils;
*/
public class ReactiveAdapterRegistry {
+ private static final boolean reactorPresent =
+ ClassUtils.isPresent("reactor.core.publisher.Flux", ReactiveAdapterRegistry.class.getClassLoader());
+
private static final boolean rxJava1Present =
ClassUtils.isPresent("rx.Observable", ReactiveAdapterRegistry.class.getClassLoader());
@@ -67,35 +70,14 @@ public class ReactiveAdapterRegistry {
*/
public ReactiveAdapterRegistry() {
- // Flux and Mono ahead of Publisher...
-
- registerReactiveType(
- ReactiveTypeDescriptor.singleOptionalValue(Mono.class, Mono::empty),
- source -> (Mono>) source,
- Mono::from
- );
-
- registerReactiveType(ReactiveTypeDescriptor.multiValue(Flux.class, Flux::empty),
- source -> (Flux>) source,
- Flux::from);
-
- registerReactiveType(ReactiveTypeDescriptor.multiValue(Publisher.class, Flux::empty),
- source -> (Publisher>) source,
- source -> source);
-
- registerReactiveType(
- ReactiveTypeDescriptor.singleOptionalValue(CompletableFuture.class, () -> {
- CompletableFuture> empty = new CompletableFuture<>();
- empty.complete(null);
- return empty;
- }),
- source -> Mono.fromFuture((CompletableFuture>) source),
- source -> Mono.from(source).toFuture()
- );
+ if (reactorPresent) {
+ new ReactorRegistrar().registerAdapters(this);
+ }
if (rxJava1Present && rxJava1Adapter) {
new RxJava1Registrar().registerAdapters(this);
}
+
if (rxJava2Present) {
new RxJava2Registrar().registerAdapters(this);
}
@@ -110,7 +92,12 @@ public class ReactiveAdapterRegistry {
public void registerReactiveType(ReactiveTypeDescriptor descriptor,
Function