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)
This commit is contained in:
Dave Syer 2014-09-19 16:02:29 +01:00
parent 6248fc0d60
commit d6165d97dd
3 changed files with 8 additions and 7 deletions

View File

@ -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");
}

View File

@ -48,10 +48,10 @@ public class PropertySourcesPropertyValues implements PropertyValues {
private final PropertySources propertySources;
private final Collection<String> NON_ENUMERABLE_ENUMERABLES = Arrays.asList(
private static final Collection<String> 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;
}

View File

@ -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());