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:
parent
6248fc0d60
commit
d6165d97dd
|
|
@ -74,6 +74,11 @@ class OnWebApplicationCondition extends SpringBootCondition {
|
||||||
.match("found web application StandardServletEnvironment");
|
.match("found web application StandardServletEnvironment");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (context.getResourceLoader() instanceof WebApplicationContext) {
|
||||||
|
return ConditionOutcome
|
||||||
|
.match("found web application WebApplicationContext");
|
||||||
|
}
|
||||||
|
|
||||||
return ConditionOutcome.noMatch("not a web application");
|
return ConditionOutcome.noMatch("not a web application");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -48,10 +48,10 @@ public class PropertySourcesPropertyValues implements PropertyValues {
|
||||||
|
|
||||||
private final PropertySources propertySources;
|
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_ENVIRONMENT_PROPERTY_SOURCE_NAME,
|
||||||
StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME);
|
StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new PropertyValues from the given PropertySources
|
* Create a new PropertyValues from the given PropertySources
|
||||||
* @param propertySources a PropertySources instance
|
* @param propertySources a PropertySources instance
|
||||||
|
|
@ -107,7 +107,7 @@ public class PropertySourcesPropertyValues implements PropertyValues {
|
||||||
PropertySourcesPropertyResolver resolver, String[] includes, String[] exacts) {
|
PropertySourcesPropertyResolver resolver, String[] includes, String[] exacts) {
|
||||||
if (source.getPropertyNames().length > 0) {
|
if (source.getPropertyNames().length > 0) {
|
||||||
for (String propertyName : source.getPropertyNames()) {
|
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)) {
|
&& !PatternMatchUtils.simpleMatch(includes, propertyName)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,6 @@ import org.springframework.test.context.web.WebMergedContextConfiguration;
|
||||||
import org.springframework.util.ObjectUtils;
|
import org.springframework.util.ObjectUtils;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
import org.springframework.web.context.support.GenericWebApplicationContext;
|
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
|
* 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();
|
SpringApplication application = getSpringApplication();
|
||||||
application.setSources(getSources(config));
|
application.setSources(getSources(config));
|
||||||
ConfigurableEnvironment environment = new StandardEnvironment();
|
ConfigurableEnvironment environment = new StandardEnvironment();
|
||||||
if (config instanceof WebMergedContextConfiguration) {
|
|
||||||
environment = new StandardServletEnvironment();
|
|
||||||
}
|
|
||||||
if (!ObjectUtils.isEmpty(config.getActiveProfiles())) {
|
if (!ObjectUtils.isEmpty(config.getActiveProfiles())) {
|
||||||
String profiles = StringUtils.arrayToCommaDelimitedString(config
|
String profiles = StringUtils.arrayToCommaDelimitedString(config
|
||||||
.getActiveProfiles());
|
.getActiveProfiles());
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue