Search in sources :

Example 1 with PropertySourceLoader

use of org.springframework.boot.env.PropertySourceLoader in project cloudbreak by hortonworks.

the class AppConfig method init.

@PostConstruct
public void init() throws IOException {
    Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
    ResourcePatternResolver patternResolver = new PathMatchingResourcePatternResolver();
    PropertySourceLoader load = new YamlPropertySourceLoader();
    for (Resource resource : patternResolver.getResources("classpath*:*-images.yml")) {
        environment.getPropertySources().addLast(load.load(resource.getFilename(), resource, null));
    }
    for (Resource resource : loadEtcResources()) {
        environment.getPropertySources().addFirst(load.load(resource.getFilename(), resource, null));
    }
}
Also used : PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) ResourcePatternResolver(org.springframework.core.io.support.ResourcePatternResolver) PropertySourceLoader(org.springframework.boot.env.PropertySourceLoader) YamlPropertySourceLoader(org.springframework.boot.env.YamlPropertySourceLoader) Resource(org.springframework.core.io.Resource) YamlPropertySourceLoader(org.springframework.boot.env.YamlPropertySourceLoader) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) PostConstruct(javax.annotation.PostConstruct)

Example 2 with PropertySourceLoader

use of org.springframework.boot.env.PropertySourceLoader in project spring-boot by spring-projects.

the class StandardConfigDataLocationResolver method getReferencesForFile.

private Set<StandardConfigDataReference> getReferencesForFile(ConfigDataLocation configDataLocation, String file, String profile) {
    Matcher extensionHintMatcher = EXTENSION_HINT_PATTERN.matcher(file);
    boolean extensionHintLocation = extensionHintMatcher.matches();
    if (extensionHintLocation) {
        file = extensionHintMatcher.group(1) + extensionHintMatcher.group(2);
    }
    for (PropertySourceLoader propertySourceLoader : this.propertySourceLoaders) {
        String extension = getLoadableFileExtension(propertySourceLoader, file);
        if (extension != null) {
            String root = file.substring(0, file.length() - extension.length() - 1);
            StandardConfigDataReference reference = new StandardConfigDataReference(configDataLocation, null, root, profile, (!extensionHintLocation) ? extension : null, propertySourceLoader);
            return Collections.singleton(reference);
        }
    }
    throw new IllegalStateException("File extension is not known to any PropertySourceLoader. " + "If the location is meant to reference a directory, it must end in '/' or File.separator");
}
Also used : Matcher(java.util.regex.Matcher) PropertySourceLoader(org.springframework.boot.env.PropertySourceLoader)

Aggregations

PropertySourceLoader (org.springframework.boot.env.PropertySourceLoader)2 Matcher (java.util.regex.Matcher)1 PostConstruct (javax.annotation.PostConstruct)1 YamlPropertySourceLoader (org.springframework.boot.env.YamlPropertySourceLoader)1 Resource (org.springframework.core.io.Resource)1 PathMatchingResourcePatternResolver (org.springframework.core.io.support.PathMatchingResourcePatternResolver)1 ResourcePatternResolver (org.springframework.core.io.support.ResourcePatternResolver)1