Search in sources :

Example 1 with YamlPropertySourceLoader

use of org.springframework.boot.env.YamlPropertySourceLoader 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 YamlPropertySourceLoader

use of org.springframework.boot.env.YamlPropertySourceLoader in project spring-cloud-open-service-broker by spring-cloud.

the class ServiceBrokerPropertiesValidationTest method bindMinimumValidYaml.

@Test
public void bindMinimumValidYaml() throws Exception {
    this.context.register(ServiceBrokerPropertiesConfiguration.class);
    Resource resource = context.getResource("classpath:catalog-minimal.yml");
    YamlPropertySourceLoader sourceLoader = new YamlPropertySourceLoader();
    List<PropertySource<?>> properties = sourceLoader.load("catalog", resource);
    context.getEnvironment().getPropertySources().addFirst(properties.get(0));
    validateMinimumCatalog();
}
Also used : Resource(org.springframework.core.io.Resource) YamlPropertySourceLoader(org.springframework.boot.env.YamlPropertySourceLoader) PropertySource(org.springframework.core.env.PropertySource) Test(org.junit.Test)

Example 3 with YamlPropertySourceLoader

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

the class StandardConfigDataLoaderTests method loadWhenLocationResultsInMultiplePropertySourcesAddsAllToConfigData.

@Test
void loadWhenLocationResultsInMultiplePropertySourcesAddsAllToConfigData() throws IOException {
    ClassPathResource resource = new ClassPathResource("configdata/yaml/application.yml");
    StandardConfigDataReference reference = new StandardConfigDataReference(ConfigDataLocation.of("classpath:configdata/yaml/application.yml"), null, "classpath:configdata/yaml/application", null, "yml", new YamlPropertySourceLoader());
    StandardConfigDataResource location = new StandardConfigDataResource(reference, resource);
    ConfigData configData = this.loader.load(this.loaderContext, location);
    assertThat(configData.getPropertySources().size()).isEqualTo(2);
    PropertySource<?> source1 = configData.getPropertySources().get(0);
    PropertySource<?> source2 = configData.getPropertySources().get(1);
    assertThat(source1.getName()).isEqualTo("Config resource 'class path resource [configdata/yaml/application.yml]' " + "via location 'classpath:configdata/yaml/application.yml' (document #0)");
    assertThat(source1.getProperty("foo")).isEqualTo("bar");
    assertThat(source2.getName()).isEqualTo("Config resource 'class path resource [configdata/yaml/application.yml]' " + "via location 'classpath:configdata/yaml/application.yml' (document #1)");
    assertThat(source2.getProperty("hello")).isEqualTo("world");
}
Also used : YamlPropertySourceLoader(org.springframework.boot.env.YamlPropertySourceLoader) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.jupiter.api.Test)

Example 4 with YamlPropertySourceLoader

use of org.springframework.boot.env.YamlPropertySourceLoader in project syndesis by syndesisio.

the class SyndesisCommand method createContext.

private AbstractApplicationContext createContext() {
    final AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
    final YamlPropertySourceLoader propertySourceLoader = new YamlPropertySourceLoader();
    final PropertySource<?> propertySource;
    try {
        propertySource = propertySourceLoader.load(name, context.getResource("classpath:" + name + ".yml"), null);
    } catch (final IOException e) {
        throw new IllegalStateException(e);
    }
    final StandardEnvironment environment = new StandardEnvironment();
    final MutablePropertySources propertySources = environment.getPropertySources();
    propertySources.addFirst(new MapPropertySource("parameters", parameters));
    propertySources.addLast(propertySource);
    context.setEnvironment(environment);
    final String packageName = getClass().getPackage().getName();
    context.scan(packageName);
    context.refresh();
    return context;
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) MapPropertySource(org.springframework.core.env.MapPropertySource) YamlPropertySourceLoader(org.springframework.boot.env.YamlPropertySourceLoader) IOException(java.io.IOException) MutablePropertySources(org.springframework.core.env.MutablePropertySources) StandardEnvironment(org.springframework.core.env.StandardEnvironment)

Example 5 with YamlPropertySourceLoader

use of org.springframework.boot.env.YamlPropertySourceLoader in project spring-cloud-open-service-broker by spring-cloud.

the class ServiceBrokerPropertiesBindingTest method bindMinimumValidYaml.

@Test
void bindMinimumValidYaml() throws Exception {
    this.context.register(ServiceBrokerPropertiesConfiguration.class);
    Resource resource = context.getResource("classpath:catalog-minimal.yml");
    YamlPropertySourceLoader sourceLoader = new YamlPropertySourceLoader();
    List<PropertySource<?>> properties = sourceLoader.load("catalog", resource);
    context.getEnvironment().getPropertySources().addFirst(properties.get(0));
    validateMinimumCatalog();
}
Also used : Resource(org.springframework.core.io.Resource) YamlPropertySourceLoader(org.springframework.boot.env.YamlPropertySourceLoader) PropertySource(org.springframework.core.env.PropertySource) Test(org.junit.jupiter.api.Test)

Aggregations

YamlPropertySourceLoader (org.springframework.boot.env.YamlPropertySourceLoader)6 Resource (org.springframework.core.io.Resource)4 Test (org.junit.jupiter.api.Test)3 PropertySource (org.springframework.core.env.PropertySource)3 IOException (java.io.IOException)1 PostConstruct (javax.annotation.PostConstruct)1 Test (org.junit.Test)1 PropertySourceLoader (org.springframework.boot.env.PropertySourceLoader)1 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)1 MapPropertySource (org.springframework.core.env.MapPropertySource)1 MutablePropertySources (org.springframework.core.env.MutablePropertySources)1 StandardEnvironment (org.springframework.core.env.StandardEnvironment)1 ClassPathResource (org.springframework.core.io.ClassPathResource)1 PathMatchingResourcePatternResolver (org.springframework.core.io.support.PathMatchingResourcePatternResolver)1 ResourcePatternResolver (org.springframework.core.io.support.ResourcePatternResolver)1