Skip to content

Commit 070eeda

Browse files
committed
Configure RouteMatcher at the RSocketStrategies level
After a change in Spring Framework (see spring-projects/spring-framework#23314), the `RouteMatcher` to be used with the RSocket infrastructure is configured on the `RSocketStrategies` directly. This commit moves the auto-configuration of the `PathPatternRouteMatcher` from the message handling parts to the RSocket strategy one. Closes gh-17571
1 parent 185d9a3 commit 070eeda

File tree

4 files changed

+10
-13
lines changed

4 files changed

+10
-13
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/rsocket/RSocketMessagingAutoConfiguration.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828
import org.springframework.messaging.rsocket.RSocketRequester;
2929
import org.springframework.messaging.rsocket.RSocketStrategies;
3030
import org.springframework.messaging.rsocket.annotation.support.RSocketMessageHandler;
31-
import org.springframework.util.ClassUtils;
32-
import org.springframework.web.util.pattern.PathPatternRouteMatcher;
3331

3432
/**
3533
* {@link EnableAutoConfiguration Auto-configuration} for Spring RSocket support in Spring
@@ -43,16 +41,11 @@
4341
@AutoConfigureAfter(RSocketStrategiesAutoConfiguration.class)
4442
public class RSocketMessagingAutoConfiguration {
4543

46-
private static final String PATHPATTERN_ROUTEMATCHER_CLASS = "org.springframework.web.util.pattern.PathPatternRouteMatcher";
47-
4844
@Bean
4945
@ConditionalOnMissingBean
5046
public RSocketMessageHandler messageHandler(RSocketStrategies rSocketStrategies) {
5147
RSocketMessageHandler messageHandler = new RSocketMessageHandler();
5248
messageHandler.setRSocketStrategies(rSocketStrategies);
53-
if (ClassUtils.isPresent(PATHPATTERN_ROUTEMATCHER_CLASS, null)) {
54-
messageHandler.setRouteMatcher(new PathPatternRouteMatcher());
55-
}
5649
return messageHandler;
5750
}
5851

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/rsocket/RSocketStrategiesAutoConfiguration.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
import org.springframework.http.codec.json.Jackson2JsonEncoder;
4040
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
4141
import org.springframework.messaging.rsocket.RSocketStrategies;
42+
import org.springframework.util.ClassUtils;
43+
import org.springframework.web.util.pattern.PathPatternRouteMatcher;
4244

4345
/**
4446
* {@link EnableAutoConfiguration Auto-configuration} for {@link RSocketStrategies}.
@@ -51,10 +53,15 @@
5153
@AutoConfigureAfter(JacksonAutoConfiguration.class)
5254
public class RSocketStrategiesAutoConfiguration {
5355

56+
private static final String PATHPATTERN_ROUTEMATCHER_CLASS = "org.springframework.web.util.pattern.PathPatternRouteMatcher";
57+
5458
@Bean
5559
@ConditionalOnMissingBean
5660
public RSocketStrategies rSocketStrategies(ObjectProvider<RSocketStrategiesCustomizer> customizers) {
5761
RSocketStrategies.Builder builder = RSocketStrategies.builder();
62+
if (ClassUtils.isPresent(PATHPATTERN_ROUTEMATCHER_CLASS, null)) {
63+
builder.routeMatcher(new PathPatternRouteMatcher());
64+
}
5865
customizers.orderedStream().forEach((customizer) -> customizer.customize(builder));
5966
return builder.build();
6067
}

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/rsocket/RSocketMessagingAutoConfigurationTests.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import org.springframework.core.codec.StringDecoder;
2727
import org.springframework.messaging.rsocket.RSocketStrategies;
2828
import org.springframework.messaging.rsocket.annotation.support.RSocketMessageHandler;
29-
import org.springframework.web.util.pattern.PathPatternRouteMatcher;
3029

3130
import static org.assertj.core.api.Assertions.assertThat;
3231

@@ -43,11 +42,7 @@ class RSocketMessagingAutoConfigurationTests {
4342

4443
@Test
4544
void shouldCreateDefaultBeans() {
46-
this.contextRunner.run((context) -> {
47-
assertThat(context).getBeans(RSocketMessageHandler.class).hasSize(1);
48-
assertThat(context.getBean(RSocketMessageHandler.class).getRouteMatcher())
49-
.isInstanceOf(PathPatternRouteMatcher.class);
50-
});
45+
this.contextRunner.run((context) -> assertThat(context).getBeans(RSocketMessageHandler.class).hasSize(1));
5146
}
5247

5348
@Test

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/rsocket/RSocketStrategiesAutoConfigurationTests.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.springframework.http.codec.json.Jackson2JsonDecoder;
3434
import org.springframework.http.codec.json.Jackson2JsonEncoder;
3535
import org.springframework.messaging.rsocket.RSocketStrategies;
36+
import org.springframework.web.util.pattern.PathPatternRouteMatcher;
3637

3738
import static org.assertj.core.api.Assertions.assertThat;
3839
import static org.mockito.Mockito.mock;
@@ -56,6 +57,7 @@ void shouldCreateDefaultBeans() {
5657
.hasAtLeastOneElementOfType(Jackson2JsonDecoder.class);
5758
assertThat(strategies.encoders()).hasAtLeastOneElementOfType(Jackson2CborEncoder.class)
5859
.hasAtLeastOneElementOfType(Jackson2JsonEncoder.class);
60+
assertThat(strategies.routeMatcher()).isInstanceOf(PathPatternRouteMatcher.class);
5961
});
6062
}
6163

0 commit comments

Comments
 (0)