|
|
@ -104,6 +104,8 @@ public class ConfigFileApplicationListener implements
|
|
|
|
|
|
|
|
|
|
|
|
private PropertySourceAnnotations propertySourceAnnotations = new PropertySourceAnnotations();
|
|
|
|
private PropertySourceAnnotations propertySourceAnnotations = new PropertySourceAnnotations();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private PropertySourceLoaderFactory propertySourceLoaderFactory = new DefaultPropertySourceLoaderFactory();
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Binds the early {@link Environment} to the {@link SpringApplication}. This makes it
|
|
|
|
* Binds the early {@link Environment} to the {@link SpringApplication}. This makes it
|
|
|
|
* possible to set {@link SpringApplication} properties dynamically, like the sources
|
|
|
|
* possible to set {@link SpringApplication} properties dynamically, like the sources
|
|
|
@ -284,12 +286,8 @@ public class ConfigFileApplicationListener implements
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
List<PropertySourceLoader> loaders = new ArrayList<PropertySourceLoader>();
|
|
|
|
List<PropertySourceLoader> loaders = this.propertySourceLoaderFactory
|
|
|
|
loaders.add(new PropertiesPropertySourceLoader());
|
|
|
|
.getLoaders(environment);
|
|
|
|
if (ClassUtils.isPresent("org.yaml.snakeyaml.Yaml", null)) {
|
|
|
|
|
|
|
|
loaders.add(YamlPropertySourceLoader.springProfileAwareLoader(environment
|
|
|
|
|
|
|
|
.getActiveProfiles()));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Resource resource = resourceLoader.getResource(location);
|
|
|
|
Resource resource = resourceLoader.getResource(location);
|
|
|
|
String name = this.propertySourceAnnotations.name(location);
|
|
|
|
String name = this.propertySourceAnnotations.name(location);
|
|
|
@ -334,13 +332,23 @@ public class ConfigFileApplicationListener implements
|
|
|
|
if (this.cached.containsKey(key)) {
|
|
|
|
if (this.cached.containsKey(key)) {
|
|
|
|
return this.cached.get(key);
|
|
|
|
return this.cached.get(key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
boolean satisfied = true;
|
|
|
|
for (PropertySourceLoader loader : loaders) {
|
|
|
|
for (PropertySourceLoader loader : loaders) {
|
|
|
|
if (resource != null && resource.exists() && loader.supports(resource)) {
|
|
|
|
if (resource != null && resource.exists()) {
|
|
|
|
PropertySource<?> propertySource = loader.load(name, resource);
|
|
|
|
if (loader.supports(resource)) {
|
|
|
|
this.cached.put(key, propertySource);
|
|
|
|
PropertySource<?> propertySource = loader.load(name, resource);
|
|
|
|
return propertySource;
|
|
|
|
this.cached.put(key, propertySource);
|
|
|
|
|
|
|
|
return propertySource;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
satisfied = false;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!satisfied) {
|
|
|
|
|
|
|
|
throw new IllegalStateException(
|
|
|
|
|
|
|
|
"No supported loader found for configuration resource: " + resource);
|
|
|
|
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -368,6 +376,14 @@ public class ConfigFileApplicationListener implements
|
|
|
|
this.searchLocations = (searchLocations == null ? null : searchLocations.clone());
|
|
|
|
this.searchLocations = (searchLocations == null ? null : searchLocations.clone());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @param propertySourceLoaderFactory the factory to set
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public void setPropertySourceLoaderFactory(
|
|
|
|
|
|
|
|
PropertySourceLoaderFactory propertySourceLoaderFactory) {
|
|
|
|
|
|
|
|
this.propertySourceLoaderFactory = propertySourceLoaderFactory;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static class RandomValuePropertySource extends PropertySource<Random> {
|
|
|
|
private static class RandomValuePropertySource extends PropertySource<Random> {
|
|
|
|
|
|
|
|
|
|
|
|
public RandomValuePropertySource(String name) {
|
|
|
|
public RandomValuePropertySource(String name) {
|
|
|
@ -444,4 +460,24 @@ public class ConfigFileApplicationListener implements
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static interface PropertySourceLoaderFactory {
|
|
|
|
|
|
|
|
List<PropertySourceLoader> getLoaders(Environment environment);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static class DefaultPropertySourceLoaderFactory implements
|
|
|
|
|
|
|
|
PropertySourceLoaderFactory {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public List<PropertySourceLoader> getLoaders(Environment environment) {
|
|
|
|
|
|
|
|
ArrayList<PropertySourceLoader> loaders = new ArrayList<PropertySourceLoader>();
|
|
|
|
|
|
|
|
loaders.add(new PropertiesPropertySourceLoader());
|
|
|
|
|
|
|
|
if (ClassUtils.isPresent("org.yaml.snakeyaml.Yaml", null)) {
|
|
|
|
|
|
|
|
loaders.add(YamlPropertySourceLoader.springProfileAwareLoader(environment
|
|
|
|
|
|
|
|
.getActiveProfiles()));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return loaders;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|