use of org.springframework.beans.factory.config.YamlPropertiesFactoryBean in project alien4cloud by alien4cloud.
the class LdapCondition method matches.
@Override
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
YamlPropertiesFactoryBean propertiesFactoryBean = AlienYamlPropertiesFactoryBeanFactory.get(context.getResourceLoader());
Object ldapEnabled = propertiesFactoryBean.getObject().get("ldap.enabled");
if (ldapEnabled != null && ldapEnabled instanceof Boolean) {
return ((Boolean) ldapEnabled).booleanValue();
}
return false;
}
use of org.springframework.beans.factory.config.YamlPropertiesFactoryBean in project Asqatasun by Asqatasun.
the class AsqatasunTestConfig method propertySourcesPlaceholderConfigurer.
@Bean
public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer = new PropertySourcesPlaceholderConfigurer();
YamlPropertiesFactoryBean yaml = new YamlPropertiesFactoryBean();
yaml.setResources(new ClassPathResource("application-test.yml"));
propertySourcesPlaceholderConfigurer.setProperties(yaml.getObject());
return propertySourcesPlaceholderConfigurer;
}
use of org.springframework.beans.factory.config.YamlPropertiesFactoryBean in project swift by luastar.
the class ClassLoaderUtils method getProperties.
/**
* 将资源文件转化为Properties对象
* 基于classloader实现
*
* @param resource 资源文件
* @return
*/
/*
public static Properties getProperties(String resource) {
try {
Properties properties = new Properties();
InputStream is = getClassLoader().getResourceAsStream(resource);
if (is != null) {
properties.load(new BufferedReader(new InputStreamReader(is)));
}
return properties;
} catch (IOException e) {
return new Properties();
}
}
*/
/**
* 将资源文件转化为Properties对象
* 基于spring实现
*
* @param resource 资源文件
* @return
*/
public static Properties getProperties(String... resource) {
Properties properties = new Properties();
if (resource == null || resource.length == 0) {
return properties;
}
YamlPropertiesFactoryBean yaml = new YamlPropertiesFactoryBean();
for (String resPath : resource) {
try {
Resource[] resourceArray = getResourcePatternResolver().getResources(resPath);
if (resourceArray != null) {
for (Resource res : resourceArray) {
if (FilenameUtils.isExtension(resPath, "yml")) {
logger.info("加载配置文件:{}", res.getDescription());
yaml.setResources(res);
properties.putAll(yaml.getObject());
} else if (FilenameUtils.isExtension(resPath, "properties")) {
logger.info("加载配置文件:{}", res.getDescription());
PropertiesLoaderUtils.fillProperties(properties, new EncodedResource(res, "UTF-8"));
} else {
logger.warn("忽略不识别的文件类型,目前仅支持properties和yml文件:{}", res.getDescription());
}
}
}
} catch (IOException e) {
logger.error(e.getMessage(), e);
}
}
for (Map.Entry<Object, Object> entry : properties.entrySet()) {
logger.info("配置文件变量:{} = {}", entry.getKey(), entry.getValue());
}
return properties;
}
use of org.springframework.beans.factory.config.YamlPropertiesFactoryBean in project spring-boot by spring-projects.
the class SpringProfileDocumentMatcherTests method getProperties.
private Properties getProperties(String values) throws IOException {
YamlPropertiesFactoryBean yamlPropertiesFactoryBean = new YamlPropertiesFactoryBean();
ByteArrayResource resource = new ByteArrayResource(values.getBytes());
yamlPropertiesFactoryBean.setResources(resource);
yamlPropertiesFactoryBean.afterPropertiesSet();
return yamlPropertiesFactoryBean.getObject();
}
use of org.springframework.beans.factory.config.YamlPropertiesFactoryBean in project spring-cloud-config by spring-cloud.
the class VaultEnvironmentRepository method findOne.
@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);
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;
}
Aggregations