From d6165d97dde27faff1e19c97281ea4e026a9f6d4 Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Fri, 19 Sep 2014 16:02:29 +0100 Subject: [PATCH] A few tweaks that might improve performance on startup ... or couldn't hurt anyway. 1. Extends the definition of a web application for @ConditionalOnWebapp so that a StandardEnvironment can be used (cutting out JNDI failures for Environment properties) 2. Doesn't bother using StandardServletEnvironment in integration tests 3. Make the NON_ENUMERABLE_ENUMERABLES in PropertySourcesPropertyValues static so they only get initialized once (not a huge issue at all) --- .../autoconfigure/condition/OnWebApplicationCondition.java | 5 +++++ .../boot/bind/PropertySourcesPropertyValues.java | 6 +++--- .../boot/test/SpringApplicationContextLoader.java | 4 ---- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/OnWebApplicationCondition.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/OnWebApplicationCondition.java index c6b53c46b88..0224181ab60 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/OnWebApplicationCondition.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/OnWebApplicationCondition.java @@ -74,6 +74,11 @@ class OnWebApplicationCondition extends SpringBootCondition { .match("found web application StandardServletEnvironment"); } + if (context.getResourceLoader() instanceof WebApplicationContext) { + return ConditionOutcome + .match("found web application WebApplicationContext"); + } + return ConditionOutcome.noMatch("not a web application"); } diff --git a/spring-boot/src/main/java/org/springframework/boot/bind/PropertySourcesPropertyValues.java b/spring-boot/src/main/java/org/springframework/boot/bind/PropertySourcesPropertyValues.java index 66746512301..d7e874d66ac 100644 --- a/spring-boot/src/main/java/org/springframework/boot/bind/PropertySourcesPropertyValues.java +++ b/spring-boot/src/main/java/org/springframework/boot/bind/PropertySourcesPropertyValues.java @@ -48,10 +48,10 @@ public class PropertySourcesPropertyValues implements PropertyValues { private final PropertySources propertySources; - private final Collection NON_ENUMERABLE_ENUMERABLES = Arrays.asList( + private static final Collection NON_ENUMERABLE_ENUMERABLES = Arrays.asList( StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME, StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME); - + /** * Create a new PropertyValues from the given PropertySources * @param propertySources a PropertySources instance @@ -107,7 +107,7 @@ public class PropertySourcesPropertyValues implements PropertyValues { PropertySourcesPropertyResolver resolver, String[] includes, String[] exacts) { if (source.getPropertyNames().length > 0) { for (String propertyName : source.getPropertyNames()) { - if (this.NON_ENUMERABLE_ENUMERABLES.contains(source.getName()) + if (PropertySourcesPropertyValues.NON_ENUMERABLE_ENUMERABLES.contains(source.getName()) && !PatternMatchUtils.simpleMatch(includes, propertyName)) { continue; } diff --git a/spring-boot/src/main/java/org/springframework/boot/test/SpringApplicationContextLoader.java b/spring-boot/src/main/java/org/springframework/boot/test/SpringApplicationContextLoader.java index e1057f9fe0e..7e957f84507 100644 --- a/spring-boot/src/main/java/org/springframework/boot/test/SpringApplicationContextLoader.java +++ b/spring-boot/src/main/java/org/springframework/boot/test/SpringApplicationContextLoader.java @@ -50,7 +50,6 @@ import org.springframework.test.context.web.WebMergedContextConfiguration; import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; import org.springframework.web.context.support.GenericWebApplicationContext; -import org.springframework.web.context.support.StandardServletEnvironment; /** * A {@link ContextLoader} that can be used to test Spring Boot applications (those that @@ -82,9 +81,6 @@ public class SpringApplicationContextLoader extends AbstractContextLoader { SpringApplication application = getSpringApplication(); application.setSources(getSources(config)); ConfigurableEnvironment environment = new StandardEnvironment(); - if (config instanceof WebMergedContextConfiguration) { - environment = new StandardServletEnvironment(); - } if (!ObjectUtils.isEmpty(config.getActiveProfiles())) { String profiles = StringUtils.arrayToCommaDelimitedString(config .getActiveProfiles());