Skip to content

Commit 7136229

Browse files
committed
Polish RSocket server bootstrap
See gh-16021
1 parent d4c47a1 commit 7136229

File tree

3 files changed

+15
-16
lines changed

3 files changed

+15
-16
lines changed

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

+7-6
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@
1818

1919
import java.util.stream.Collectors;
2020

21-
import io.netty.buffer.PooledByteBufAllocator;
2221
import io.rsocket.RSocketFactory;
2322
import io.rsocket.SocketAcceptor;
23+
import io.rsocket.transport.netty.server.TcpServerTransport;
24+
import reactor.netty.http.server.HttpServer;
2425

2526
import org.springframework.beans.factory.ObjectProvider;
2627
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
@@ -33,7 +34,7 @@
3334
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
3435
import org.springframework.boot.context.properties.EnableConfigurationProperties;
3536
import org.springframework.boot.context.properties.PropertyMapper;
36-
import org.springframework.boot.rsocket.netty.NettyRSocketBootstrap;
37+
import org.springframework.boot.rsocket.server.RSocketServerBootstrap;
3738
import org.springframework.boot.rsocket.netty.NettyRSocketServerFactory;
3839
import org.springframework.boot.rsocket.server.RSocketServerFactory;
3940
import org.springframework.boot.rsocket.server.ServerRSocketFactoryCustomizer;
@@ -57,8 +58,8 @@
5758
* @since 2.2.0
5859
*/
5960
@Configuration(proxyBeanMethods = false)
60-
@ConditionalOnClass({ RSocketFactory.class, RSocketStrategies.class,
61-
PooledByteBufAllocator.class })
61+
@ConditionalOnClass({ RSocketFactory.class, RSocketStrategies.class, HttpServer.class,
62+
TcpServerTransport.class })
6263
@ConditionalOnBean(MessageHandlerAcceptor.class)
6364
@AutoConfigureAfter(RSocketStrategiesAutoConfiguration.class)
6465
@EnableConfigurationProperties(RSocketProperties.class)
@@ -105,10 +106,10 @@ public RSocketServerFactory rSocketServerFactory(RSocketProperties properties,
105106
}
106107

107108
@Bean
108-
public NettyRSocketBootstrap nettyRSocketBootstrap(
109+
public RSocketServerBootstrap nettyRSocketBootstrap(
109110
RSocketServerFactory rSocketServerFactory,
110111
SocketAcceptor socketAcceptor) {
111-
return new NettyRSocketBootstrap(rSocketServerFactory, socketAcceptor);
112+
return new RSocketServerBootstrap(rSocketServerFactory, socketAcceptor);
112113
}
113114

114115
}

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import org.junit.Test;
2020

2121
import org.springframework.boot.autoconfigure.AutoConfigurations;
22-
import org.springframework.boot.rsocket.netty.NettyRSocketBootstrap;
22+
import org.springframework.boot.rsocket.server.RSocketServerBootstrap;
2323
import org.springframework.boot.rsocket.server.RSocketServerFactory;
2424
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
2525
import org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner;
@@ -46,7 +46,7 @@ public void shouldNotCreateBeansByDefault() {
4646
contextRunner.run((context) -> assertThat(context)
4747
.doesNotHaveBean(WebServerFactoryCustomizer.class)
4848
.doesNotHaveBean(RSocketServerFactory.class)
49-
.doesNotHaveBean(NettyRSocketBootstrap.class));
49+
.doesNotHaveBean(RSocketServerBootstrap.class));
5050
}
5151

5252
@Test
@@ -55,7 +55,7 @@ public void shouldNotCreateDefaultBeansForReactiveWebAppWithoutMapping() {
5555
contextRunner.run((context) -> assertThat(context)
5656
.doesNotHaveBean(WebServerFactoryCustomizer.class)
5757
.doesNotHaveBean(RSocketServerFactory.class)
58-
.doesNotHaveBean(NettyRSocketBootstrap.class));
58+
.doesNotHaveBean(RSocketServerBootstrap.class));
5959
}
6060

6161
@Test
@@ -67,7 +67,7 @@ public void shouldNotCreateDefaultBeansForReactiveWebAppWithWrongTransport() {
6767
.run((context) -> assertThat(context)
6868
.doesNotHaveBean(WebServerFactoryCustomizer.class)
6969
.doesNotHaveBean(RSocketServerFactory.class)
70-
.doesNotHaveBean(NettyRSocketBootstrap.class));
70+
.doesNotHaveBean(RSocketServerBootstrap.class));
7171
}
7272

7373
@Test
@@ -87,7 +87,7 @@ public void shouldCreateDefaultBeansForRSocketServerWhenPortIsSet() {
8787
contextRunner.withPropertyValues("spring.rsocket.server.port=0")
8888
.run((context) -> assertThat(context)
8989
.hasSingleBean(RSocketServerFactory.class)
90-
.hasSingleBean(NettyRSocketBootstrap.class));
90+
.hasSingleBean(RSocketServerBootstrap.class));
9191
}
9292

9393
private ApplicationContextRunner createContextRunner() {
+3-5
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,11 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.boot.rsocket.netty;
17+
package org.springframework.boot.rsocket.server;
1818

1919
import io.rsocket.SocketAcceptor;
2020

2121
import org.springframework.boot.rsocket.context.RSocketServerInitializedEvent;
22-
import org.springframework.boot.rsocket.server.RSocketServer;
23-
import org.springframework.boot.rsocket.server.RSocketServerFactory;
2422
import org.springframework.context.ApplicationEventPublisher;
2523
import org.springframework.context.ApplicationEventPublisherAware;
2624
import org.springframework.context.SmartLifecycle;
@@ -31,14 +29,14 @@
3129
* @author Brian Clozel
3230
* @since 2.2.0
3331
*/
34-
public class NettyRSocketBootstrap
32+
public class RSocketServerBootstrap
3533
implements ApplicationEventPublisherAware, SmartLifecycle {
3634

3735
private final RSocketServer rSocketServer;
3836

3937
private ApplicationEventPublisher applicationEventPublisher;
4038

41-
public NettyRSocketBootstrap(RSocketServerFactory serverFactoryProvider,
39+
public RSocketServerBootstrap(RSocketServerFactory serverFactoryProvider,
4240
SocketAcceptor socketAcceptor) {
4341
this.rSocketServer = serverFactoryProvider.create(socketAcceptor);
4442
}

0 commit comments

Comments
 (0)