Commit 2104d9a1 authored by Dave Syer's avatar Dave Syer

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.
parent c03a06b5
......@@ -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 {
}
......
......@@ -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();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment