Search in sources :

Example 11 with YamlPropertiesFactoryBean

use of org.springframework.beans.factory.config.YamlPropertiesFactoryBean in project alien4cloud by alien4cloud.

the class FullApplicationConfiguration method properties.

@Bean
public static PropertySourcesPlaceholderConfigurer properties(ResourceLoader resourceLoader) {
    PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer = new PropertySourcesPlaceholderConfigurer();
    YamlPropertiesFactoryBean yaml = AlienYamlPropertiesFactoryBeanFactory.get(resourceLoader);
    propertySourcesPlaceholderConfigurer.setProperties(yaml.getObject());
    return propertySourcesPlaceholderConfigurer;
}
Also used : YamlPropertiesFactoryBean(org.springframework.beans.factory.config.YamlPropertiesFactoryBean) PropertySourcesPlaceholderConfigurer(org.springframework.context.support.PropertySourcesPlaceholderConfigurer) YamlPropertiesFactoryBean(org.springframework.beans.factory.config.YamlPropertiesFactoryBean) Bean(org.springframework.context.annotation.Bean)

Example 12 with YamlPropertiesFactoryBean

use of org.springframework.beans.factory.config.YamlPropertiesFactoryBean in project java-chassis by ServiceComb.

the class ConfigConverter method createFileSource.

private Map<String, Object> createFileSource(Object v) {
    YamlPropertiesFactoryBean yamlFactory = new YamlPropertiesFactoryBean();
    yamlFactory.setResources(new ByteArrayResource(v.toString().getBytes(Charset.forName("UTF-8"))));
    return propertiesToMap(yamlFactory.getObject());
}
Also used : YamlPropertiesFactoryBean(org.springframework.beans.factory.config.YamlPropertiesFactoryBean) ByteArrayResource(org.springframework.core.io.ByteArrayResource)

Example 13 with YamlPropertiesFactoryBean

use of org.springframework.beans.factory.config.YamlPropertiesFactoryBean in project java-chassis by ServiceComb.

the class KieClient method processValueType.

private Map<String, Object> processValueType(KVDoc kvDoc) {
    ValueType valueType;
    try {
        valueType = ValueType.valueOf(kvDoc.getValueType());
    } catch (IllegalArgumentException e) {
        throw new OperationException("value type not support");
    }
    Properties properties = new Properties();
    Map<String, Object> kvMap = new HashMap<>();
    try {
        switch(valueType) {
            case yml:
            case yaml:
                YamlPropertiesFactoryBean yamlFactory = new YamlPropertiesFactoryBean();
                yamlFactory.setResources(new ByteArrayResource(kvDoc.getValue().getBytes()));
                return toMap(yamlFactory.getObject());
            case properties:
                properties.load(new StringReader(kvDoc.getValue()));
                return toMap(properties);
            case text:
            case string:
            default:
                kvMap.put(kvDoc.getKey(), kvDoc.getValue());
                return kvMap;
        }
    } catch (Exception e) {
        LOGGER.error("read config failed");
    }
    return Collections.emptyMap();
}
Also used : ValueType(org.apache.servicecomb.config.kie.client.model.ValueType) HashMap(java.util.HashMap) StringReader(java.io.StringReader) YamlPropertiesFactoryBean(org.springframework.beans.factory.config.YamlPropertiesFactoryBean) ByteArrayResource(org.springframework.core.io.ByteArrayResource) Properties(java.util.Properties) OperationException(org.apache.servicecomb.config.kie.client.exception.OperationException) OperationException(org.apache.servicecomb.config.kie.client.exception.OperationException)

Example 14 with YamlPropertiesFactoryBean

use of org.springframework.beans.factory.config.YamlPropertiesFactoryBean in project java-chassis by ServiceComb.

the class YamlParser method parse.

@Override
public Map<String, Object> parse(String content, String prefix, boolean addPrefix) {
    YamlPropertiesFactoryBean yamlFactory = new YamlPropertiesFactoryBean();
    yamlFactory.setResources(new ByteArrayResource(content.getBytes()));
    Properties properties = yamlFactory.getObject();
    return Parser.propertiesToMap(properties, prefix, addPrefix);
}
Also used : YamlPropertiesFactoryBean(org.springframework.beans.factory.config.YamlPropertiesFactoryBean) ByteArrayResource(org.springframework.core.io.ByteArrayResource) Properties(java.util.Properties)

Example 15 with YamlPropertiesFactoryBean

use of org.springframework.beans.factory.config.YamlPropertiesFactoryBean in project gravitee-gateway by gravitee-io.

the class PropertiesConfiguration method graviteeProperties.

@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);
    Properties properties = yaml.getObject();
    LOGGER.info("Loading Gravitee configuration. DONE");
    return properties;
}
Also used : FileSystemResource(org.springframework.core.io.FileSystemResource) Resource(org.springframework.core.io.Resource) YamlPropertiesFactoryBean(org.springframework.beans.factory.config.YamlPropertiesFactoryBean) FileSystemResource(org.springframework.core.io.FileSystemResource) Properties(java.util.Properties) YamlPropertiesFactoryBean(org.springframework.beans.factory.config.YamlPropertiesFactoryBean) Bean(org.springframework.context.annotation.Bean)

Aggregations

YamlPropertiesFactoryBean (org.springframework.beans.factory.config.YamlPropertiesFactoryBean)17 Properties (java.util.Properties)6 Bean (org.springframework.context.annotation.Bean)5 ByteArrayResource (org.springframework.core.io.ByteArrayResource)5 Resource (org.springframework.core.io.Resource)4 PropertySourcesPlaceholderConfigurer (org.springframework.context.support.PropertySourcesPlaceholderConfigurer)3 FileSystemResource (org.springframework.core.io.FileSystemResource)3 Map (java.util.Map)2 ClassPathResource (org.springframework.core.io.ClassPathResource)2 JsonIgnoreProperties (com.fasterxml.jackson.annotation.JsonIgnoreProperties)1 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 HashMap (java.util.HashMap)1 lombok.val (lombok.val)1 OperationException (org.apache.servicecomb.config.kie.client.exception.OperationException)1 ValueType (org.apache.servicecomb.config.kie.client.model.ValueType)1 Environment (org.springframework.cloud.config.environment.Environment)1 PropertySource (org.springframework.cloud.config.environment.PropertySource)1 EncodedResource (org.springframework.core.io.support.EncodedResource)1