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

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

Introduction

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

Prototype

YamlPropertiesFactoryBean

Source Link

Usage

From source file:io.gravitee.gateway.env.PropertiesConfiguration.java

@Bean(name = "graviteeProperties")
public static Properties graviteeProperties() throws IOException {
    LOGGER.info("Loading Gravitee configuration.");

    YamlPropertiesFactoryBean yaml = new YamlPropertiesFactoryBean();

    String yamlConfiguration = System.getProperty(GRAVITEE_CONFIGURATION);
    Resource yamlResource = new FileSystemResource(yamlConfiguration);

    LOGGER.info("\tGravitee configuration loaded from {}", yamlResource.getURL().getPath());

    yaml.setResources(yamlResource);//from w  w  w . j  a v  a 2 s . c  o  m
    Properties properties = yaml.getObject();
    LOGGER.info("Loading Gravitee configuration. DONE");

    return properties;
}

From source file:io.gravitee.management.rest.spring.PropertiesConfiguration.java

@Bean(name = "graviteeProperties")
public static Properties graviteeProperties() throws IOException {
    LOGGER.info("Loading Gravitee Management configuration.");

    YamlPropertiesFactoryBean yaml = new YamlPropertiesFactoryBean();

    String yamlConfiguration = System.getProperty(GRAVITEE_CONFIGURATION);
    Resource yamlResource = new FileSystemResource(yamlConfiguration);

    LOGGER.info("\tGravitee Management configuration loaded from {}", yamlResource.getURL().getPath());

    yaml.setResources(yamlResource);//from   w ww  . j  a  v  a  2 s  .  c  o  m
    Properties properties = yaml.getObject();
    LOGGER.info("Loading Gravitee Management configuration. DONE");

    return properties;
}

From source file:io.gravitee.repository.jdbc.config.JdbcRepositoryConfigurationTest.java

@Bean
public static Properties graviteeProperties() {
    final YamlPropertiesFactoryBean yaml = new YamlPropertiesFactoryBean();
    final Resource yamlResource = new ClassPathResource("gravitee.yml");
    yaml.setResources(yamlResource);/*from w w w.j  a  va2  s. c  om*/
    return yaml.getObject();
}

From source file:io.gravitee.management.war.utils.PropertiesLoader.java

public Properties load() {
    YamlPropertiesFactoryBean yaml = new YamlPropertiesFactoryBean();

    String yamlConfiguration = System.getProperty(GRAVITEE_CONFIGURATION);
    Resource yamlResource = new FileSystemResource(yamlConfiguration);

    yaml.setResources(yamlResource);//from  w ww  .  j a  v  a 2 s.c om
    Properties properties = yaml.getObject();

    return properties;
}

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();/*  w  w w  .j  a v a 2s  . co  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;
}

From source file:com.example.journal.env.JournalEnvironmentPostProcessor.java

private void contributeDefaults(Map<String, Object> defaults, Resource resource) {
    if (resource.exists()) {
        YamlPropertiesFactoryBean yamlPropertiesFactoryBean = new YamlPropertiesFactoryBean();
        yamlPropertiesFactoryBean.setResources(resource);
        yamlPropertiesFactoryBean.afterPropertiesSet();
        Properties p = yamlPropertiesFactoryBean.getObject();
        for (Object k : p.keySet()) {
            String key = k.toString();
            defaults.put(key, p.get(key));
        }/*  w ww .j  a  v a  2 s. c  o  m*/
    }
}

From source file:org.springframework.cloud.config.server.environment.VaultEnvironmentRepository.java

@Override
public Environment findOne(String application, String profile, String label) {

    String state = request.getHeader(STATE_HEADER);
    String newState = this.watch.watch(state);

    String[] profiles = StringUtils.commaDelimitedListToStringArray(profile);
    List<String> scrubbedProfiles = scrubProfiles(profiles);

    List<String> keys = findKeys(application, scrubbedProfiles);

    Environment environment = new Environment(application, profiles, label, null, newState);

    for (String key : keys) {
        // read raw 'data' key from vault
        String data = read(key);//from  ww w. jav  a 2  s. c om
        if (data != null) {
            // data is in json format of which, yaml is a superset, so parse
            final YamlPropertiesFactoryBean yaml = new YamlPropertiesFactoryBean();
            yaml.setResources(new ByteArrayResource(data.getBytes()));
            Properties properties = yaml.getObject();

            if (!properties.isEmpty()) {
                environment.add(new PropertySource("vault:" + key, properties));
            }
        }
    }

    return environment;
}

From source file:io.spring.initializr.metadata.InitializrMetadataBuilderTests.java

private static Properties loadProperties(Resource resource) {
    YamlPropertiesFactoryBean yamlFactory = new YamlPropertiesFactoryBean();
    yamlFactory.setResources(resource);//w ww.ja v a  2 s  . com
    yamlFactory.afterPropertiesSet();
    return yamlFactory.getObject();
}

From source file:org.springframework.cloud.dataflow.rest.util.DeploymentPropertiesUtils.java

/**
 * Parses a deployment properties conditionally either from properties
 * string or file which can be legacy properties file or yaml.
 *
 * @param deploymentProperties the deployment properties string
 * @param propertiesFile the deployment properties file
 * @param which the flag to choose between properties or file
 * @return the map of parsed properties// ww  w  .  jav  a 2  s . co  m
 * @throws IOException if file loading errors
 */
public static Map<String, String> parseDeploymentProperties(String deploymentProperties, File propertiesFile,
        int which) throws IOException {
    Map<String, String> propertiesToUse;
    switch (which) {
    case 0:
        propertiesToUse = parse(deploymentProperties);
        break;
    case 1:
        String extension = FilenameUtils.getExtension(propertiesFile.getName());
        Properties props = null;
        if (extension.equals("yaml") || extension.equals("yml")) {
            YamlPropertiesFactoryBean yamlPropertiesFactoryBean = new YamlPropertiesFactoryBean();
            yamlPropertiesFactoryBean.setResources(new FileSystemResource(propertiesFile));
            yamlPropertiesFactoryBean.afterPropertiesSet();
            props = yamlPropertiesFactoryBean.getObject();
        } else {
            props = new Properties();
            try (FileInputStream fis = new FileInputStream(propertiesFile)) {
                props.load(fis);
            }
        }
        propertiesToUse = convert(props);
        break;
    case -1: // Neither option specified
        propertiesToUse = new HashMap<>(1);
        break;
    default:
        throw new AssertionError();
    }
    return propertiesToUse;
}

From source file:org.springframework.cloud.dataflow.server.config.DefaultEnvironmentPostProcessor.java

private static void contributeDefaults(Map<String, Object> defaults, Resource resource) {
    if (resource.exists()) {
        YamlPropertiesFactoryBean yamlPropertiesFactoryBean = new YamlPropertiesFactoryBean();
        yamlPropertiesFactoryBean.setResources(resource);
        yamlPropertiesFactoryBean.afterPropertiesSet();
        Properties p = yamlPropertiesFactoryBean.getObject();
        for (Object k : p.keySet()) {
            String key = k.toString();
            defaults.put(key, p.get(key));
        }/*from   w w  w .ja v  a 2  s  .c o  m*/
    }
}