From 27c1b5eb4c1310fd11c3865394747d3a769abe4d Mon Sep 17 00:00:00 2001 From: Brian Clozel Date: Tue, 5 Sep 2017 11:51:11 +0200 Subject: [PATCH] Add "onClass" condition on web server auto-configurations This commit adds new Conditional annotations on auto-configurations creating the Servlet/Reactive web servers. These conditions only depend on request primitives used by the servers themselves and aren't framework specific. Closes gh-10163 --- .../web/reactive/ReactiveWebServerAutoConfiguration.java | 3 +++ .../web/servlet/ServletWebServerFactoryAutoConfiguration.java | 2 ++ 2 files changed, 5 insertions(+) diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/ReactiveWebServerAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/ReactiveWebServerAutoConfiguration.java index 25558bcc324..0625988738a 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/ReactiveWebServerAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/ReactiveWebServerAutoConfiguration.java @@ -24,6 +24,7 @@ import org.springframework.beans.factory.support.BeanDefinitionRegistry; import org.springframework.beans.factory.support.RootBeanDefinition; import org.springframework.boot.autoconfigure.AutoConfigureOrder; 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.web.ServerProperties; @@ -35,6 +36,7 @@ import org.springframework.context.annotation.Import; import org.springframework.context.annotation.ImportBeanDefinitionRegistrar; import org.springframework.core.Ordered; import org.springframework.core.type.AnnotationMetadata; +import org.springframework.http.ReactiveHttpInputMessage; import org.springframework.util.ObjectUtils; /** @@ -45,6 +47,7 @@ import org.springframework.util.ObjectUtils; */ @AutoConfigureOrder(Ordered.HIGHEST_PRECEDENCE) @Configuration +@ConditionalOnClass(ReactiveHttpInputMessage.class) @ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.REACTIVE) @EnableConfigurationProperties(ServerProperties.class) @Import({ ReactiveWebServerAutoConfiguration.BeanPostProcessorsRegistrar.class, diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/ServletWebServerFactoryAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/ServletWebServerFactoryAutoConfiguration.java index 1650cda982d..aabf0e2af15 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/ServletWebServerFactoryAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/ServletWebServerFactoryAutoConfiguration.java @@ -17,6 +17,7 @@ package org.springframework.boot.autoconfigure.web.servlet; import javax.servlet.Servlet; +import javax.servlet.ServletRequest; import io.undertow.Undertow; import org.apache.catalina.startup.Tomcat; @@ -66,6 +67,7 @@ import org.springframework.util.ObjectUtils; */ @AutoConfigureOrder(Ordered.HIGHEST_PRECEDENCE) @Configuration +@ConditionalOnClass(ServletRequest.class) @ConditionalOnWebApplication(type = Type.SERVLET) @EnableConfigurationProperties(ServerProperties.class) @Import(BeanPostProcessorsRegistrar.class)