From 2104d9a1e2609065502324ba7c42fb02b7957efc Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Fri, 29 Nov 2013 17:40:14 +0000 Subject: [PATCH] Prevent failure of web app with parent context ServerProperties formerly had an @OnMissingBeanCondition that didn't restrict the hierarchy. It also asserts that the current context (not including parents) contains such a bean. This led to an inevitable failure when there was an existing instance in the parent context. Fixed by a) searching only the current context, b) not adding a ServerProperties bean if the context is not a web app. --- .../web/BasicErrorControllerSpecialIntegrationTests.java | 4 +--- .../autoconfigure/web/ServerPropertiesAutoConfiguration.java | 5 ++++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/web/BasicErrorControllerSpecialIntegrationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/web/BasicErrorControllerSpecialIntegrationTests.java index dcdbfa5369..7cabdf463d 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/web/BasicErrorControllerSpecialIntegrationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/web/BasicErrorControllerSpecialIntegrationTests.java @@ -20,7 +20,6 @@ import org.junit.After; import org.junit.Test; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.context.annotation.Configuration; import org.springframework.http.MediaType; @@ -78,8 +77,7 @@ public class BasicErrorControllerSpecialIntegrationTests { } @Configuration - // TODO: fix this so it doesn't need to be excluded - @EnableAutoConfiguration(exclude = ServerPropertiesAutoConfiguration.class) + @EnableAutoConfiguration protected static class ParentConfiguration { } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerPropertiesAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerPropertiesAutoConfiguration.java index 3625643194..f84c200b29 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerPropertiesAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerPropertiesAutoConfiguration.java @@ -19,6 +19,8 @@ package org.springframework.boot.autoconfigure.web; import org.springframework.beans.BeansException; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; +import org.springframework.boot.autoconfigure.condition.SearchStrategy; import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainerFactory; import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer; import org.springframework.boot.context.properties.EnableConfigurationProperties; @@ -38,13 +40,14 @@ import org.springframework.util.StringUtils; */ @Configuration @EnableConfigurationProperties +@ConditionalOnWebApplication public class ServerPropertiesAutoConfiguration implements ApplicationContextAware, EmbeddedServletContainerCustomizer { private ApplicationContext applicationContext; @Bean(name = "org.springframework.boot.autoconfigure.web.ServerProperties") - @ConditionalOnMissingBean + @ConditionalOnMissingBean(search = SearchStrategy.CURRENT) public ServerProperties serverProperties() { return new ServerProperties(); }