Skip to content

Commit d6165d9

Browse files
author
Dave Syer
committed
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)
1 parent 6248fc0 commit d6165d9

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/OnWebApplicationCondition.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ private ConditionOutcome isWebApplication(ConditionContext context,
7474
.match("found web application StandardServletEnvironment");
7575
}
7676

77+
if (context.getResourceLoader() instanceof WebApplicationContext) {
78+
return ConditionOutcome
79+
.match("found web application WebApplicationContext");
80+
}
81+
7782
return ConditionOutcome.noMatch("not a web application");
7883
}
7984

spring-boot/src/main/java/org/springframework/boot/bind/PropertySourcesPropertyValues.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ public class PropertySourcesPropertyValues implements PropertyValues {
4848

4949
private final PropertySources propertySources;
5050

51-
private final Collection<String> NON_ENUMERABLE_ENUMERABLES = Arrays.asList(
51+
private static final Collection<String> NON_ENUMERABLE_ENUMERABLES = Arrays.asList(
5252
StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME,
5353
StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME);
54-
54+
5555
/**
5656
* Create a new PropertyValues from the given PropertySources
5757
* @param propertySources a PropertySources instance
@@ -107,7 +107,7 @@ private void processEnumerablePropertySource(EnumerablePropertySource<?> source,
107107
PropertySourcesPropertyResolver resolver, String[] includes, String[] exacts) {
108108
if (source.getPropertyNames().length > 0) {
109109
for (String propertyName : source.getPropertyNames()) {
110-
if (this.NON_ENUMERABLE_ENUMERABLES.contains(source.getName())
110+
if (PropertySourcesPropertyValues.NON_ENUMERABLE_ENUMERABLES.contains(source.getName())
111111
&& !PatternMatchUtils.simpleMatch(includes, propertyName)) {
112112
continue;
113113
}

spring-boot/src/main/java/org/springframework/boot/test/SpringApplicationContextLoader.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
import org.springframework.util.ObjectUtils;
5151
import org.springframework.util.StringUtils;
5252
import org.springframework.web.context.support.GenericWebApplicationContext;
53-
import org.springframework.web.context.support.StandardServletEnvironment;
5453

5554
/**
5655
* A {@link ContextLoader} that can be used to test Spring Boot applications (those that
@@ -82,9 +81,6 @@ public ApplicationContext loadContext(MergedContextConfiguration config)
8281
SpringApplication application = getSpringApplication();
8382
application.setSources(getSources(config));
8483
ConfigurableEnvironment environment = new StandardEnvironment();
85-
if (config instanceof WebMergedContextConfiguration) {
86-
environment = new StandardServletEnvironment();
87-
}
8884
if (!ObjectUtils.isEmpty(config.getActiveProfiles())) {
8985
String profiles = StringUtils.arrayToCommaDelimitedString(config
9086
.getActiveProfiles());

0 commit comments

Comments
 (0)