Example usage for org.springframework.beans.factory.config YamlPropertiesFactoryBean setDocumentMatchers

List of usage examples for org.springframework.beans.factory.config YamlPropertiesFactoryBean setDocumentMatchers

Introduction

In this page you can find the example usage for org.springframework.beans.factory.config YamlPropertiesFactoryBean setDocumentMatchers.

Prototype

public void setDocumentMatchers(DocumentMatcher... matchers) 

Source Link

Document

A map of document matchers allowing callers to selectively use only some of the documents in a YAML resource.

Usage

From source file:org.zalando.crypto.spring.boot.EncryptedYamlPropertySourceLoader.java

@Override
public PropertySource<?> load(final String name, final Resource resource, final String profile)
        throws IOException {
    validateDecrypter();/*from ww  w  . j a va2 s.  c o  m*/
    if (ClassUtils.isPresent("org.yaml.snakeyaml.Yaml", null)) {
        YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean();
        if (profile == null) {
            factory.setMatchDefault(true);
            factory.setDocumentMatchers(new SpringProfileDocumentMatcher());
        } else {
            factory.setMatchDefault(false);
            factory.setDocumentMatchers(new SpringProfileDocumentMatcher(profile));
        }

        factory.setResources(new Resource[] { resource });

        Properties properties = factory.getObject();
        if (!properties.isEmpty()) {
            return new PropertiesPropertySource(name,
                    new EncryptableProperties(properties, decrypter, getPrefix()));
        }
    }

    return null;
}