From 84637acbdc4a601f35b9e23ba0a00e33a2bccfd1 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Tue, 9 Mar 2021 08:53:25 +0000 Subject: [PATCH] Make embedded RSocket server back off without spring-web Fixes gh-25551 --- .../rsocket/RSocketServerAutoConfiguration.java | 3 ++- .../RSocketServerAutoConfigurationTests.java | 14 +++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/rsocket/RSocketServerAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/rsocket/RSocketServerAutoConfiguration.java index 866d7ed147..7b998194e4 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/rsocket/RSocketServerAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/rsocket/RSocketServerAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -81,6 +81,7 @@ public class RSocketServerAutoConfiguration { } @ConditionalOnProperty(prefix = "spring.rsocket.server", name = "port") + @ConditionalOnClass(ReactorResourceFactory.class) @Configuration(proxyBeanMethods = false) static class EmbeddedServerAutoConfiguration { diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/rsocket/RSocketServerAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/rsocket/RSocketServerAutoConfigurationTests.java index 2134011e8a..06881ae968 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/rsocket/RSocketServerAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/rsocket/RSocketServerAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,10 +19,13 @@ package org.springframework.boot.autoconfigure.rsocket; import org.junit.jupiter.api.Test; import org.springframework.boot.autoconfigure.AutoConfigurations; +import org.springframework.boot.autoconfigure.logging.ConditionEvaluationReportLoggingListener; +import org.springframework.boot.logging.LogLevel; import org.springframework.boot.rsocket.context.RSocketPortInfoApplicationContextInitializer; import org.springframework.boot.rsocket.context.RSocketServerBootstrap; import org.springframework.boot.rsocket.server.RSocketServerCustomizer; import org.springframework.boot.rsocket.server.RSocketServerFactory; +import org.springframework.boot.test.context.FilteredClassLoader; import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner; import org.springframework.boot.web.server.WebServerFactoryCustomizer; @@ -30,6 +33,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.codec.CharSequenceEncoder; import org.springframework.core.codec.StringDecoder; +import org.springframework.http.client.reactive.ReactorResourceFactory; import org.springframework.messaging.rsocket.RSocketStrategies; import org.springframework.messaging.rsocket.annotation.support.RSocketMessageHandler; @@ -106,6 +110,14 @@ class RSocketServerAutoConfigurationTests { .containsExactly("customNettyRouteProvider")); } + @Test + void whenSpringWebIsNotPresentThenEmbeddedServerConfigurationBacksOff() { + contextRunner().withClassLoader(new FilteredClassLoader(ReactorResourceFactory.class)) + .withInitializer(new ConditionEvaluationReportLoggingListener(LogLevel.INFO)) + .withPropertyValues("spring.rsocket.server.port=0") + .run((context) -> assertThat(context).doesNotHaveBean(RSocketServerFactory.class)); + } + private ApplicationContextRunner contextRunner() { return new ApplicationContextRunner().withUserConfiguration(BaseConfiguration.class) .withConfiguration(AutoConfigurations.of(RSocketServerAutoConfiguration.class));