Skip to content

Commit 3beb074

Browse files
committed
Remove support for RxJava 1.x
Also removes unnecessary flowPublisherPresent check on JDK 9+, depending on Reactor presence for its JDK Flow adapter instead. Closes gh-27443
1 parent 5ab789b commit 3beb074

File tree

4 files changed

+13
-121
lines changed

4 files changed

+13
-121
lines changed

build.gradle

-2
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,6 @@ configure(allprojects) { project ->
6464
entry 'groovy-xml'
6565
}
6666

67-
dependency "io.reactivex:rxjava:1.3.8"
68-
dependency "io.reactivex:rxjava-reactive-streams:1.2.1"
6967
dependency "io.reactivex.rxjava2:rxjava:2.2.21"
7068
dependency "io.reactivex.rxjava3:rxjava:3.1.1"
7169
dependency "io.smallrye.reactive:mutiny:1.0.0"

spring-core/spring-core.gradle

-2
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ dependencies {
4444
optional("org.jetbrains.kotlinx:kotlinx-coroutines-core")
4545
optional("org.jetbrains.kotlinx:kotlinx-coroutines-reactor")
4646
optional("io.projectreactor:reactor-core")
47-
optional("io.reactivex:rxjava")
48-
optional("io.reactivex:rxjava-reactive-streams")
4947
optional("io.reactivex.rxjava2:rxjava")
5048
optional("io.reactivex.rxjava3:rxjava")
5149
optional("io.smallrye.reactive:mutiny")

spring-core/src/main/java/org/springframework/core/ReactiveAdapterRegistry.java

+11-55
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import reactor.blockhound.integration.BlockHoundIntegration;
3333
import reactor.core.publisher.Flux;
3434
import reactor.core.publisher.Mono;
35-
import rx.RxReactiveStreams;
3635

3736
import org.springframework.lang.Nullable;
3837
import org.springframework.util.ClassUtils;
@@ -44,15 +43,12 @@
4443
* {@code Observable}, and others.
4544
*
4645
* <p>By default, depending on classpath availability, adapters are registered
47-
* for Reactor, RxJava 2/3, or RxJava 1 (+ RxJava Reactive Streams bridge),
48-
* {@link CompletableFuture}, Java 9+ {@code Flow.Publisher}, and Kotlin
49-
* Coroutines' {@code Deferred} and {@code Flow}.
50-
*
51-
* <p><strong>Note:</strong> As of Spring Framework 5.3, support for RxJava 1.x
52-
* is deprecated in favor of RxJava 2 and 3.
46+
* for Reactor, RxJava 2/3, {@link CompletableFuture}, {@code Flow.Publisher},
47+
* and Kotlin Coroutines' {@code Deferred} and {@code Flow}.
5348
*
5449
* @author Rossen Stoyanchev
5550
* @author Sebastien Deleuze
51+
* @author Juergen Hoeller
5652
* @since 5.0
5753
*/
5854
public class ReactiveAdapterRegistry {
@@ -62,26 +58,19 @@ public class ReactiveAdapterRegistry {
6258

6359
private static final boolean reactorPresent;
6460

65-
private static final boolean rxjava1Present;
66-
6761
private static final boolean rxjava2Present;
6862

6963
private static final boolean rxjava3Present;
7064

71-
private static final boolean flowPublisherPresent;
72-
7365
private static final boolean kotlinCoroutinesPresent;
7466

7567
private static final boolean mutinyPresent;
7668

7769
static {
7870
ClassLoader classLoader = ReactiveAdapterRegistry.class.getClassLoader();
7971
reactorPresent = ClassUtils.isPresent("reactor.core.publisher.Flux", classLoader);
80-
rxjava1Present = ClassUtils.isPresent("rx.Observable", classLoader) &&
81-
ClassUtils.isPresent("rx.RxReactiveStreams", classLoader);
8272
rxjava2Present = ClassUtils.isPresent("io.reactivex.Flowable", classLoader);
8373
rxjava3Present = ClassUtils.isPresent("io.reactivex.rxjava3.core.Flowable", classLoader);
84-
flowPublisherPresent = ClassUtils.isPresent("java.util.concurrent.Flow.Publisher", classLoader);
8574
kotlinCoroutinesPresent = ClassUtils.isPresent("kotlinx.coroutines.reactor.MonoKt", classLoader);
8675
mutinyPresent = ClassUtils.isPresent("io.smallrye.mutiny.Multi", classLoader);
8776
}
@@ -97,29 +86,17 @@ public ReactiveAdapterRegistry() {
9786
// Reactor
9887
if (reactorPresent) {
9988
new ReactorRegistrar().registerAdapters(this);
89+
new ReactorJdkFlowAdapterRegistrar().registerAdapter(this);
10090
}
10191

102-
// RxJava1 (deprecated)
103-
if (rxjava1Present) {
104-
new RxJava1Registrar().registerAdapters(this);
105-
}
106-
107-
// RxJava2
92+
// RxJava
10893
if (rxjava2Present) {
10994
new RxJava2Registrar().registerAdapters(this);
11095
}
111-
// RxJava3
11296
if (rxjava3Present) {
11397
new RxJava3Registrar().registerAdapters(this);
11498
}
11599

116-
// Java 9+ Flow.Publisher
117-
if (flowPublisherPresent) {
118-
new ReactorJdkFlowAdapterRegistrar().registerAdapter(this);
119-
}
120-
// If not present, do nothing for the time being...
121-
// We can fall back on "reactive-streams-flow-bridge" (once released)
122-
123100
// Kotlin Coroutines
124101
if (reactorPresent && kotlinCoroutinesPresent) {
125102
new CoroutinesRegistrar().registerAdapters(this);
@@ -253,23 +230,14 @@ void registerAdapters(ReactiveAdapterRegistry registry) {
253230
}
254231

255232

256-
private static class RxJava1Registrar {
233+
private static class ReactorJdkFlowAdapterRegistrar {
257234

258-
void registerAdapters(ReactiveAdapterRegistry registry) {
259-
registry.registerReactiveType(
260-
ReactiveTypeDescriptor.multiValue(rx.Observable.class, rx.Observable::empty),
261-
source -> RxReactiveStreams.toPublisher((rx.Observable<?>) source),
262-
RxReactiveStreams::toObservable
263-
);
264-
registry.registerReactiveType(
265-
ReactiveTypeDescriptor.singleRequiredValue(rx.Single.class),
266-
source -> RxReactiveStreams.toPublisher((rx.Single<?>) source),
267-
RxReactiveStreams::toSingle
268-
);
235+
void registerAdapter(ReactiveAdapterRegistry registry) {
236+
Flow.Publisher<?> emptyFlow = JdkFlowAdapter.publisherToFlowPublisher(Flux.empty());
269237
registry.registerReactiveType(
270-
ReactiveTypeDescriptor.noValue(rx.Completable.class, rx.Completable::complete),
271-
source -> RxReactiveStreams.toPublisher((rx.Completable) source),
272-
RxReactiveStreams::toCompletable
238+
ReactiveTypeDescriptor.multiValue(Flow.Publisher.class, () -> emptyFlow),
239+
source -> JdkFlowAdapter.flowPublisherToFlux((Flow.Publisher<?>) source),
240+
JdkFlowAdapter::publisherToFlowPublisher
273241
);
274242
}
275243
}
@@ -347,18 +315,6 @@ void registerAdapters(ReactiveAdapterRegistry registry) {
347315
}
348316
}
349317

350-
private static class ReactorJdkFlowAdapterRegistrar {
351-
352-
void registerAdapter(ReactiveAdapterRegistry registry) {
353-
Flow.Publisher<?> emptyFlow = JdkFlowAdapter.publisherToFlowPublisher(Flux.empty());
354-
registry.registerReactiveType(
355-
ReactiveTypeDescriptor.multiValue(Flow.Publisher.class, () -> emptyFlow),
356-
source -> JdkFlowAdapter.flowPublisherToFlux((Flow.Publisher<?>) source),
357-
JdkFlowAdapter::publisherToFlowPublisher
358-
);
359-
}
360-
}
361-
362318

363319
/**
364320
* ReactiveAdapter variant that wraps adapted Publishers as {@link Flux} or

spring-core/src/test/java/org/springframework/core/ReactiveAdapterRegistryTests.java

+2-62
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -35,6 +35,7 @@
3535

3636
/**
3737
* Unit tests for {@link ReactiveAdapterRegistry}.
38+
*
3839
* @author Rossen Stoyanchev
3940
*/
4041
@SuppressWarnings("unchecked")
@@ -117,67 +118,6 @@ void fromCompletableFuture() {
117118
}
118119
}
119120

120-
@Nested
121-
class RxJava1 {
122-
123-
@Test
124-
void defaultAdapterRegistrations() {
125-
assertThat(getAdapter(rx.Observable.class)).isNotNull();
126-
assertThat(getAdapter(rx.Single.class)).isNotNull();
127-
assertThat(getAdapter(rx.Completable.class)).isNotNull();
128-
}
129-
130-
@Test
131-
void toObservable() {
132-
List<Integer> sequence = Arrays.asList(1, 2, 3);
133-
Publisher<Integer> source = Flux.fromIterable(sequence);
134-
Object target = getAdapter(rx.Observable.class).fromPublisher(source);
135-
assertThat(target instanceof rx.Observable).isTrue();
136-
assertThat(((rx.Observable<?>) target).toList().toBlocking().first()).isEqualTo(sequence);
137-
}
138-
139-
@Test
140-
void toSingle() {
141-
Publisher<Integer> source = Flux.fromArray(new Integer[] {1});
142-
Object target = getAdapter(rx.Single.class).fromPublisher(source);
143-
assertThat(target instanceof rx.Single).isTrue();
144-
assertThat(((rx.Single<Integer>) target).toBlocking().value()).isEqualTo(Integer.valueOf(1));
145-
}
146-
147-
@Test
148-
void toCompletable() {
149-
Publisher<Integer> source = Flux.fromArray(new Integer[] {1, 2, 3});
150-
Object target = getAdapter(rx.Completable.class).fromPublisher(source);
151-
assertThat(target instanceof rx.Completable).isTrue();
152-
assertThat(((rx.Completable) target).get()).isNull();
153-
}
154-
155-
@Test
156-
void fromObservable() {
157-
List<Integer> sequence = Arrays.asList(1, 2, 3);
158-
Object source = rx.Observable.from(sequence);
159-
Object target = getAdapter(rx.Observable.class).toPublisher(source);
160-
assertThat(target instanceof Flux).as("Expected Flux Publisher: " + target.getClass().getName()).isTrue();
161-
assertThat(((Flux<Integer>) target).collectList().block(ONE_SECOND)).isEqualTo(sequence);
162-
}
163-
164-
@Test
165-
void fromSingle() {
166-
Object source = rx.Single.just(1);
167-
Object target = getAdapter(rx.Single.class).toPublisher(source);
168-
assertThat(target instanceof Mono).as("Expected Mono Publisher: " + target.getClass().getName()).isTrue();
169-
assertThat(((Mono<Integer>) target).block(ONE_SECOND)).isEqualTo(Integer.valueOf(1));
170-
}
171-
172-
@Test
173-
void fromCompletable() {
174-
Object source = rx.Completable.complete();
175-
Object target = getAdapter(rx.Completable.class).toPublisher(source);
176-
assertThat(target instanceof Mono).as("Expected Mono Publisher: " + target.getClass().getName()).isTrue();
177-
((Mono<Void>) target).block(ONE_SECOND);
178-
}
179-
}
180-
181121
@Nested
182122
class RxJava2 {
183123

0 commit comments

Comments
 (0)