diff --git a/spring-cloud-context/src/main/java/org/springframework/cloud/bootstrap/config/PropertySourceBootstrapConfiguration.java b/spring-cloud-context/src/main/java/org/springframework/cloud/bootstrap/config/PropertySourceBootstrapConfiguration.java index 01a52250..d9e37684 100644 --- a/spring-cloud-context/src/main/java/org/springframework/cloud/bootstrap/config/PropertySourceBootstrapConfiguration.java +++ b/spring-cloud-context/src/main/java/org/springframework/cloud/bootstrap/config/PropertySourceBootstrapConfiguration.java @@ -99,7 +99,7 @@ public class PropertySourceBootstrapConfiguration implements ConfigurableEnvironment environment = applicationContext.getEnvironment(); for (PropertySourceLocator locator : this.propertySourceLocators) { Collection> source = locator.locateCollection(environment); - if (source == null) { + if (source == null || source.size() == 0) { continue; } List sourceList = new ArrayList<>(); diff --git a/spring-cloud-context/src/main/java/org/springframework/cloud/bootstrap/config/PropertySourceLocator.java b/spring-cloud-context/src/main/java/org/springframework/cloud/bootstrap/config/PropertySourceLocator.java index 24332e1e..d6dc46cf 100644 --- a/spring-cloud-context/src/main/java/org/springframework/cloud/bootstrap/config/PropertySourceLocator.java +++ b/spring-cloud-context/src/main/java/org/springframework/cloud/bootstrap/config/PropertySourceLocator.java @@ -16,8 +16,10 @@ package org.springframework.cloud.bootstrap.config; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import java.util.Collections; import java.util.List; import org.springframework.core.env.CompositePropertySource; @@ -43,8 +45,19 @@ public interface PropertySourceLocator { default Collection> locateCollection(Environment environment) { PropertySource propertySource = locate(environment); + if (propertySource == null) { + return Collections.EMPTY_LIST; + } if (CompositePropertySource.class.isInstance(propertySource)) { - return ((CompositePropertySource) propertySource).getPropertySources(); + Collection> sources = ((CompositePropertySource) propertySource) + .getPropertySources(); + List> filteredSources = new ArrayList<>(); + for (PropertySource p : sources) { + if (p != null) { + filteredSources.add(p); + } + } + return filteredSources; } else { return (List) Arrays.asList(propertySource);