Browse Source

Merge pull request #49695 from kwondh5217

* kwondh5217/main:
  Add @ConditionalOnWebApplication to NettyReactiveWebServerAutoConfiguration

Closes gh-49695
pull/49741/head
Phillip Webb 2 weeks ago
parent
commit
6dcd2de370
  1. 4
      module/spring-boot-reactor-netty/src/main/java/org/springframework/boot/reactor/netty/autoconfigure/NettyReactiveWebServerAutoConfiguration.java
  2. 11
      module/spring-boot-reactor-netty/src/test/java/org/springframework/boot/reactor/netty/autoconfigure/NettyReactiveWebServerAutoConfigurationTests.java

4
module/spring-boot-reactor-netty/src/main/java/org/springframework/boot/reactor/netty/autoconfigure/NettyReactiveWebServerAutoConfiguration.java

@ -23,6 +23,8 @@ import org.springframework.boot.autoconfigure.AutoConfiguration; @@ -23,6 +23,8 @@ import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.reactor.netty.NettyReactiveWebServerFactory;
import org.springframework.boot.reactor.netty.NettyRouteProvider;
@ -42,10 +44,12 @@ import org.springframework.http.client.ReactorResourceFactory; @@ -42,10 +44,12 @@ import org.springframework.http.client.ReactorResourceFactory;
* server.
*
* @author Andy Wilkinson
* @author Daeho Kwon
* @since 4.0.0
*/
@AutoConfiguration
@ConditionalOnClass({ ReactiveHttpInputMessage.class, HttpServer.class })
@ConditionalOnWebApplication(type = Type.REACTIVE)
@EnableConfigurationProperties(NettyServerProperties.class)
@Import({ ReactiveWebServerConfiguration.class, ReactorResourceFactoryConfiguration.class })
public final class NettyReactiveWebServerAutoConfiguration {

11
module/spring-boot-reactor-netty/src/test/java/org/springframework/boot/reactor/netty/autoconfigure/NettyReactiveWebServerAutoConfigurationTests.java

@ -19,10 +19,13 @@ package org.springframework.boot.reactor.netty.autoconfigure; @@ -19,10 +19,13 @@ package org.springframework.boot.reactor.netty.autoconfigure;
import org.junit.jupiter.api.Test;
import reactor.netty.http.server.HttpServer;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.reactor.netty.NettyReactiveWebServerFactory;
import org.springframework.boot.reactor.netty.NettyServerCustomizer;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.boot.web.server.autoconfigure.reactive.AbstractReactiveWebServerAutoConfigurationTests;
import org.springframework.boot.web.server.reactive.ReactiveWebServerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@ -39,6 +42,7 @@ import static org.mockito.Mockito.mock; @@ -39,6 +42,7 @@ import static org.mockito.Mockito.mock;
* @author Raheela Aslam
* @author Madhura Bhave
* @author Scott Frederick
* @author Daeho Kwon
*/
// @DirtiesUrlFactories
class NettyReactiveWebServerAutoConfigurationTests extends AbstractReactiveWebServerAutoConfigurationTests {
@ -67,6 +71,13 @@ class NettyReactiveWebServerAutoConfigurationTests extends AbstractReactiveWebSe @@ -67,6 +71,13 @@ class NettyReactiveWebServerAutoConfigurationTests extends AbstractReactiveWebSe
});
}
@Test
void autoConfigurationDoesNotApplyToNonWebApplication() {
new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(NettyReactiveWebServerAutoConfiguration.class))
.run((context) -> assertThat(context).doesNotHaveBean(ReactiveWebServerFactory.class));
}
@Configuration(proxyBeanMethods = false)
static class NettyServerCustomizerConfiguration {

Loading…
Cancel
Save