Skip to content

Commit c366dda

Browse files
committed
Avoid duplicate RSocket endpoint for WebSocket
Prior to this commit, choosing a "websocket" transport for your RSocket endpoint with `spring.rsocket.server.port` would not only expose the endpoint on that specific port, but also on the main server. This commit refines the auto-configuration condition to only add a route on the main server if the separate port is not chosen. Fixes gh-49592
1 parent 722408a commit c366dda

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ static class IsReactiveWebApplication {
148148

149149
}
150150

151-
@ConditionalOnProperty(name = "spring.rsocket.server.port", matchIfMissing = true)
151+
@ConditionalOnProperty(name = "spring.rsocket.server.port", havingValue = "false", matchIfMissing = true)
152152
static class HasNoPortConfigured {
153153

154154
}

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,17 @@ void shouldCreateDefaultBeansForReactiveWebApp() {
8484
.run((context) -> assertThat(context).hasSingleBean(RSocketWebSocketNettyRouteProvider.class));
8585
}
8686

87+
@Test
88+
void shouldNotCreateWebSocketRouteProviderWhenDedicatedPortIsSet() {
89+
reactiveWebContextRunner()
90+
.withPropertyValues("spring.rsocket.server.port=0", "spring.rsocket.server.transport=websocket",
91+
"spring.rsocket.server.mapping-path=/rsocket")
92+
.run((context) -> {
93+
assertThat(context).hasSingleBean(RSocketServerFactory.class);
94+
assertThat(context).doesNotHaveBean(RSocketWebSocketNettyRouteProvider.class);
95+
});
96+
}
97+
8798
@Test
8899
void shouldCreateDefaultBeansForRSocketServerWhenPortIsSet() {
89100
reactiveWebContextRunner().withPropertyValues("spring.rsocket.server.port=0")

0 commit comments

Comments
 (0)