Browse Source

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.
pull/138/head
Dave Syer 12 years ago
parent
commit
2104d9a1e2
  1. 4
      spring-boot-actuator/src/test/java/org/springframework/boot/actuate/web/BasicErrorControllerSpecialIntegrationTests.java
  2. 5
      spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerPropertiesAutoConfiguration.java

4
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.junit.Test;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
@ -78,8 +77,7 @@ public class BasicErrorControllerSpecialIntegrationTests {
} }
@Configuration @Configuration
// TODO: fix this so it doesn't need to be excluded @EnableAutoConfiguration
@EnableAutoConfiguration(exclude = ServerPropertiesAutoConfiguration.class)
protected static class ParentConfiguration { protected static class ParentConfiguration {
} }

5
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.beans.BeansException;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; 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.ConfigurableEmbeddedServletContainerFactory;
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer; import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
@ -38,13 +40,14 @@ import org.springframework.util.StringUtils;
*/ */
@Configuration @Configuration
@EnableConfigurationProperties @EnableConfigurationProperties
@ConditionalOnWebApplication
public class ServerPropertiesAutoConfiguration implements ApplicationContextAware, public class ServerPropertiesAutoConfiguration implements ApplicationContextAware,
EmbeddedServletContainerCustomizer { EmbeddedServletContainerCustomizer {
private ApplicationContext applicationContext; private ApplicationContext applicationContext;
@Bean(name = "org.springframework.boot.autoconfigure.web.ServerProperties") @Bean(name = "org.springframework.boot.autoconfigure.web.ServerProperties")
@ConditionalOnMissingBean @ConditionalOnMissingBean(search = SearchStrategy.CURRENT)
public ServerProperties serverProperties() { public ServerProperties serverProperties() {
return new ServerProperties(); return new ServerProperties();
} }

Loading…
Cancel
Save