From 19184bdf406461c21b3ba48873626f89b8dfc49f Mon Sep 17 00:00:00 2001
From: panos-kakos <102670093+panos-kakos@users.noreply.github.com>
Date: Thu, 7 Dec 2023 13:12:55 +0200
Subject: [PATCH] [JAVA-27761] Upgraded spring-reactive-2 to spring boot 3
(#15293)
---
.../spring-reactive-2/pom.xml | 18 ++++--
...n.java => Spring6ReactiveApplication.java} | 4 +-
.../consumer/ConsumerSSEApplication.java | 7 +-
.../reactive/urlmatch/FormHandler.java | 2 +-
.../com/baeldung/reactive/util/CpuUtils.java | 2 +-
.../staticcontent/StaticContentConfig.java | 2 +-
.../FunctionalValidationsApplication.java | 9 +--
.../model/AnnotatedRequestEntity.java | 4 +-
.../backpressure/BackpressureUnitTest.java | 64 +++++++++----------
...ernsUsingHandlerMethodIntegrationTest.java | 4 +-
10 files changed, 60 insertions(+), 56 deletions(-)
rename spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/reactive/{Spring5ReactiveApplication.java => Spring6ReactiveApplication.java} (77%)
diff --git a/spring-reactive-modules/spring-reactive-2/pom.xml b/spring-reactive-modules/spring-reactive-2/pom.xml
index a5552bfe51..fac93154c8 100644
--- a/spring-reactive-modules/spring-reactive-2/pom.xml
+++ b/spring-reactive-modules/spring-reactive-2/pom.xml
@@ -10,9 +10,10 @@
spring sample project about new features
- com.baeldung.spring.reactive
- spring-reactive-modules
- 1.0.0-SNAPSHOT
+ com.baeldung
+ parent-boot-3
+ 0.0.1-SNAPSHOT
+ ../../parent-boot-3
@@ -45,8 +46,8 @@
test
- com.github.tomakehurst
- wiremock-jre8
+ org.wiremock
+ wiremock
${wiremock.version}
test
@@ -64,6 +65,11 @@
org.springframework.boot
spring-boot-starter-tomcat
+
+ org.apache.commons
+ commons-lang3
+ ${commons-lang3.version}
+
@@ -116,7 +122,7 @@
1.0.1.RELEASE
- 2.24.0
+ 3.3.1
\ No newline at end of file
diff --git a/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/reactive/Spring5ReactiveApplication.java b/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/reactive/Spring6ReactiveApplication.java
similarity index 77%
rename from spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/reactive/Spring5ReactiveApplication.java
rename to spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/reactive/Spring6ReactiveApplication.java
index ef862dd957..f716af4a0e 100644
--- a/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/reactive/Spring5ReactiveApplication.java
+++ b/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/reactive/Spring6ReactiveApplication.java
@@ -5,10 +5,10 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
@SpringBootApplication(exclude = { RedisAutoConfiguration.class })
-public class Spring5ReactiveApplication{
+public class Spring6ReactiveApplication {
public static void main(String[] args) {
- SpringApplication.run(Spring5ReactiveApplication.class, args);
+ SpringApplication.run(Spring6ReactiveApplication.class, args);
}
}
diff --git a/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/reactive/serversentevents/consumer/ConsumerSSEApplication.java b/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/reactive/serversentevents/consumer/ConsumerSSEApplication.java
index d8edaf7fd5..bec7dd2e0c 100644
--- a/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/reactive/serversentevents/consumer/ConsumerSSEApplication.java
+++ b/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/reactive/serversentevents/consumer/ConsumerSSEApplication.java
@@ -22,9 +22,10 @@ public class ConsumerSSEApplication {
@Bean
public SecurityWebFilterChain sseConsumerSpringSecurityFilterChain(ServerHttpSecurity http) {
- http.authorizeExchange()
- .anyExchange()
- .permitAll();
+ http.authorizeExchange(auth -> auth
+ .anyExchange().permitAll()
+ )
+ .csrf(ServerHttpSecurity.CsrfSpec::disable);
return http.build();
}
diff --git a/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/reactive/urlmatch/FormHandler.java b/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/reactive/urlmatch/FormHandler.java
index 7b1fb06459..1652e2f25d 100644
--- a/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/reactive/urlmatch/FormHandler.java
+++ b/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/reactive/urlmatch/FormHandler.java
@@ -34,7 +34,7 @@ public class FormHandler {
private AtomicLong extractData(List dataBuffers) {
AtomicLong atomicLong = new AtomicLong(0);
- dataBuffers.forEach(d -> atomicLong.addAndGet(d.asByteBuffer()
+ dataBuffers.forEach(d -> atomicLong.addAndGet(d.toByteBuffer()
.array().length));
return atomicLong;
}
diff --git a/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/reactive/util/CpuUtils.java b/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/reactive/util/CpuUtils.java
index 8d16434920..20cc162cde 100644
--- a/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/reactive/util/CpuUtils.java
+++ b/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/reactive/util/CpuUtils.java
@@ -9,7 +9,7 @@ public class CpuUtils {
private static OperatingSystemMXBean operatingSystemMXBean = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
static Double getUsage() {
- return (operatingSystemMXBean.getSystemCpuLoad() / operatingSystemMXBean.getAvailableProcessors()) * 100;
+ return (operatingSystemMXBean.getCpuLoad() / operatingSystemMXBean.getAvailableProcessors()) * 100;
}
}
diff --git a/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/staticcontent/StaticContentConfig.java b/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/staticcontent/StaticContentConfig.java
index 1fbb9958e7..456eec8f84 100644
--- a/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/staticcontent/StaticContentConfig.java
+++ b/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/staticcontent/StaticContentConfig.java
@@ -23,7 +23,7 @@ public class StaticContentConfig {
GET("/"),
request -> ok()
.contentType(MediaType.TEXT_HTML)
- .syncBody(html)
+ .bodyValue(html)
);
}
diff --git a/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/validations/functional/FunctionalValidationsApplication.java b/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/validations/functional/FunctionalValidationsApplication.java
index 4cbb65dc60..bcbd4d55d7 100644
--- a/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/validations/functional/FunctionalValidationsApplication.java
+++ b/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/validations/functional/FunctionalValidationsApplication.java
@@ -15,10 +15,11 @@ public class FunctionalValidationsApplication {
@Bean
public SecurityWebFilterChain functionalValidationsSpringSecurityFilterChain(ServerHttpSecurity http) {
- http.authorizeExchange()
- .anyExchange()
- .permitAll();
- http.csrf().disable();
+ http.authorizeExchange(auth -> auth
+ .anyExchange().permitAll()
+ )
+ .csrf(ServerHttpSecurity.CsrfSpec::disable);
+
return http.build();
}
}
diff --git a/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/validations/functional/model/AnnotatedRequestEntity.java b/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/validations/functional/model/AnnotatedRequestEntity.java
index 992f07481c..6ca6c369c1 100644
--- a/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/validations/functional/model/AnnotatedRequestEntity.java
+++ b/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/validations/functional/model/AnnotatedRequestEntity.java
@@ -1,7 +1,7 @@
package com.baeldung.validations.functional.model;
-import javax.validation.constraints.NotNull;
-import javax.validation.constraints.Size;
+import jakarta.validation.constraints.NotNull;
+import jakarta.validation.constraints.Size;
import lombok.AllArgsConstructor;
import lombok.Getter;
diff --git a/spring-reactive-modules/spring-reactive-2/src/test/java/com/baeldung/backpressure/BackpressureUnitTest.java b/spring-reactive-modules/spring-reactive-2/src/test/java/com/baeldung/backpressure/BackpressureUnitTest.java
index a12d762fe5..c087e10b3f 100644
--- a/spring-reactive-modules/spring-reactive-2/src/test/java/com/baeldung/backpressure/BackpressureUnitTest.java
+++ b/spring-reactive-modules/spring-reactive-2/src/test/java/com/baeldung/backpressure/BackpressureUnitTest.java
@@ -24,49 +24,45 @@ public class BackpressureUnitTest {
);
StepVerifier.create(limit)
- .expectSubscription()
- .thenRequest(15)
- .expectNext(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
- .expectNext(11, 12, 13, 14, 15)
- .thenRequest(10)
- .expectNext(16, 17, 18, 19, 20, 21, 22, 23, 24, 25)
- .verifyComplete();
+ .expectSubscription()
+ .thenRequest(15)
+ .expectNext(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
+ .expectNext(11, 12, 13, 14, 15)
+ .thenRequest(10)
+ .expectNext(16, 17, 18, 19, 20, 21, 22, 23, 24, 25)
+ .verifyComplete();
}
@Test
public void whenRequestingChunks10_thenMessagesAreReceived() {
Flux request = Flux.range(1, 50);
- request.subscribe(
- integer -> LOGGER.debug(String.valueOf(integer)),
- err -> err.printStackTrace(),
- () -> LOGGER.debug("All 50 items have been successfully processed!!!"),
- subscription -> {
- for (int i = 0; i < 5; i++) {
- LOGGER.debug("Requesting the next 10 elements!!!");
- subscription.request(10);
- }
- }
- );
+ request.subscribe(integer -> LOGGER.debug(String.valueOf(integer)), err -> err.printStackTrace(), () -> LOGGER.debug("All 50 items have been successfully processed!!!"), subscription -> {
+ for (int i = 0; i < 5; i++) {
+ LOGGER.debug("Requesting the next 10 elements!!!");
+ subscription.request(10);
+ }
+ });
StepVerifier.create(request)
- .expectSubscription()
- .thenRequest(10)
- .expectNext(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
- .thenRequest(10)
- .expectNext(11, 12, 13, 14, 15, 16, 17, 18, 19, 20)
- .thenRequest(10)
- .expectNext(21, 22, 23, 24, 25, 26, 27 , 28, 29 ,30)
- .thenRequest(10)
- .expectNext(31, 32, 33, 34, 35, 36, 37 , 38, 39 ,40)
- .thenRequest(10)
- .expectNext(41, 42, 43, 44, 45, 46, 47 , 48, 49 ,50)
- .verifyComplete();
+ .expectSubscription()
+ .thenRequest(10)
+ .expectNext(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
+ .thenRequest(10)
+ .expectNext(11, 12, 13, 14, 15, 16, 17, 18, 19, 20)
+ .thenRequest(10)
+ .expectNext(21, 22, 23, 24, 25, 26, 27, 28, 29, 30)
+ .thenRequest(10)
+ .expectNext(31, 32, 33, 34, 35, 36, 37, 38, 39, 40)
+ .thenRequest(10)
+ .expectNext(41, 42, 43, 44, 45, 46, 47, 48, 49, 50)
+ .verifyComplete();
}
@Test
public void whenCancel_thenSubscriptionFinished() {
- Flux cancel = Flux.range(1, 10).log();
+ Flux cancel = Flux.range(1, 10)
+ .log();
cancel.subscribe(new BaseSubscriber() {
@Override
@@ -78,9 +74,9 @@ public class BackpressureUnitTest {
});
StepVerifier.create(cancel)
- .expectNext(1, 2, 3)
- .thenCancel()
- .verify();
+ .expectNext(1, 2, 3)
+ .thenCancel()
+ .verify();
}
}
diff --git a/spring-reactive-modules/spring-reactive-2/src/test/java/com/baeldung/reactive/urlmatch/PathPatternsUsingHandlerMethodIntegrationTest.java b/spring-reactive-modules/spring-reactive-2/src/test/java/com/baeldung/reactive/urlmatch/PathPatternsUsingHandlerMethodIntegrationTest.java
index 0b4607b54a..4069888dcd 100644
--- a/spring-reactive-modules/spring-reactive-2/src/test/java/com/baeldung/reactive/urlmatch/PathPatternsUsingHandlerMethodIntegrationTest.java
+++ b/spring-reactive-modules/spring-reactive-2/src/test/java/com/baeldung/reactive/urlmatch/PathPatternsUsingHandlerMethodIntegrationTest.java
@@ -8,11 +8,11 @@ import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.reactive.server.WebTestClient;
-import com.baeldung.reactive.Spring5ReactiveApplication;
+import com.baeldung.reactive.Spring6ReactiveApplication;
import com.baeldung.reactive.controller.PathPatternController;
@RunWith(SpringRunner.class)
-@SpringBootTest(classes = Spring5ReactiveApplication.class)
+@SpringBootTest(classes = Spring6ReactiveApplication.class)
@WithMockUser
public class PathPatternsUsingHandlerMethodIntegrationTest {