Java 类org.springframework.beans.factory.config.YamlPropertiesFactoryBean 实例源码

项目:graviteeio-access-management    文件:PropertiesConfiguration.java   
@Bean(name = "graviteeProperties")
public static Properties graviteeProperties() throws IOException {
    LOGGER.info("Loading configuration.");

    YamlPropertiesFactoryBean yaml = new YamlPropertiesFactoryBean();

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

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

    yaml.setResources(yamlResource);
    Properties properties = yaml.getObject();
    LOGGER.info("Loading configuration. DONE");

    return properties;
}
项目:gravitee-management-rest-api    文件: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);
    Properties properties = yaml.getObject();
    LOGGER.info("Loading Gravitee Management configuration. DONE");

    return properties;
}
项目:gravitee-gateway    文件: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);
    Properties properties = yaml.getObject();
    LOGGER.info("Loading Gravitee configuration. DONE");

    return properties;
}
项目:spring-cloud-consul    文件:ConsulPropertySource.java   
protected Properties generateProperties(String value,
        ConsulConfigProperties.Format format) {
    final Properties props = new Properties();

    if (format == PROPERTIES) {
        try {
            // Must use the ISO-8859-1 encoding because Properties.load(stream)
            // expects it.
            props.load(new ByteArrayInputStream(value.getBytes("ISO-8859-1")));
        }
        catch (IOException e) {
            throw new IllegalArgumentException(value
                    + " can't be encoded using ISO-8859-1");
        }

        return props;
    }
    else if (format == YAML) {
        final YamlPropertiesFactoryBean yaml = new YamlPropertiesFactoryBean();
        yaml.setResources(new ByteArrayResource(value.getBytes()));

        return yaml.getObject();
    }

    return props;
}
项目:cas-5.1.0    文件:CasCoreBootstrapStandaloneConfiguration.java   
private static Map<Object, Object> loadYamlProperties(final Resource... resource) {
    final YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean();
    factory.setResolutionMethod(YamlProcessor.ResolutionMethod.OVERRIDE);
    factory.setResources(resource);
    factory.setSingleton(true);
    factory.afterPropertiesSet();
    return factory.getObject();
}
项目:telemarket-skittle-alley    文件:CommonConfig.java   
@Bean
public static YamlPropertiesFactoryBean yamlPropertiesFactoryBean() {
    YamlPropertiesFactoryBean propertiesFactoryBean = new YamlPropertiesFactoryBean();
    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    try {
        Resource[] resources = resolver.getResources("/**/*.yml");
        propertiesFactoryBean.setResources(resources);
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }
    return propertiesFactoryBean;
}
项目:RFTBackend    文件:CustomYamlConfig.java   
@Bean
public PropertySourcesPlaceholderConfigurer properties() {
    PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer = new PropertySourcesPlaceholderConfigurer();
    YamlPropertiesFactoryBean yamlPropertiesFactory = new YamlPropertiesFactoryBean();
    ConfigurationFileResourceResolver configurationFileResourceResolver = new ConfigurationFileResourceResolver();

    yamlPropertiesFactory.setResources(configurationFileResourceResolver.getResourceArray());
    propertySourcesPlaceholderConfigurer.setProperties(yamlPropertiesFactory.getObject());

    return propertySourcesPlaceholderConfigurer;
}
项目:devoxxus-jhipster-microservices-demo    文件:DefaultProfileUtil.java   
/**
 * Load application.yml from classpath.
 */
private static Properties readProperties() {
    try {
        YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean();
        factory.setResources(new ClassPathResource("config/application.yml"));
        return factory.getObject();
    } catch (Exception e) {
        log.error("Failed to read application.yml to get default profile");
        return null;
    }
}
项目:spring-cloud-dashboard    文件: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));
        }
    }
}
项目:klask-io    文件:DefaultProfileUtil.java   
/**
 * Load application.yml from classpath.
 */
private static Properties readProperties() {
    try {
        YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean();
        factory.setResources(new ClassPathResource("config/application.yml"));
        return factory.getObject();
    } catch (Exception e) {
        log.error("Failed to read application.yml to get default profile");
    }
    return null;
}
项目:Microservices-with-JHipster-and-Spring-Boot    文件:DefaultProfileUtil.java   
/**
 * Load application.yml from classpath.
 */
private static Properties readProperties() {
    try {
        YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean();
        factory.setResources(new ClassPathResource("config/application.yml"));
        return factory.getObject();
    } catch (Exception e) {
        log.error("Failed to read application.yml to get default profile");
        return null;
    }
}
项目:Thesis-JHipster    文件:DefaultProfileUtil.java   
/**
 * Load application.yml from classpath.
 *
 * @return the YAML Properties
 */
private static Properties readProperties() {
    try {
        YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean();
        factory.setResources(new ClassPathResource("config/application.yml"));
        return factory.getObject();
    } catch (Exception e) {
        log.error("Failed to read application.yml to get default profile");
    }
    return null;
}
项目:Thesis-JHipster    文件:_DefaultProfileUtil.java   
/**
 * Load application.yml from classpath.
 *
 * @return the YAML Properties
 */
private static Properties readProperties() {
    try {
        YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean();
        factory.setResources(new ClassPathResource("config/application.yml"));
        return factory.getObject();
    } catch (Exception e) {
        log.error("Failed to read application.yml to get default profile");
    }
    return null;
}
项目:Thesis-JHipster    文件:DefaultProfileUtil.java   
/**
 * Load application.yml from classpath.
 */
private static Properties readProperties() {
    try {
        YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean();
        factory.setResources(new ClassPathResource("config/application.yml"));
        return factory.getObject();
    } catch (Exception e) {
        log.error("Failed to read application.yml to get default profile");
    }
    return null;
}
项目:micro-service-netflix    文件:YamlUtils.java   
public static Properties convertYamlToProperties(String yamlFile) {

    YamlPropertiesFactoryBean yamlPropertiesFactoryBean = new YamlPropertiesFactoryBean();
    yamlPropertiesFactoryBean.setResources(new ClassPathResource(yamlFile));
    yamlPropertiesFactoryBean.setResolutionMethod(ResolutionMethod.FIRST_FOUND);

    return yamlPropertiesFactoryBean.getObject();
}
项目:blackhole    文件:DefaultProfileUtil.java   
/**
 * Load application.yml from classpath.
 */
private static Properties readProperties() {
    try {
        YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean();
        factory.setResources(new ClassPathResource("config/application.yml"));
        return factory.getObject();
    } catch (Exception e) {
        log.error("Failed to read application.yml to get default profile");
    }
    return null;
}
项目:readthisstuff.com    文件:DefaultProfileUtil.java   
/**
 * Load application.yml from classpath.
 */
private static Properties readProperties() {
    try {
        YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean();
        factory.setResources(new ClassPathResource("config/application.yml"));
        return factory.getObject();
    } catch (Exception e) {
        log.error("Failed to read application.yml to get default profile");
    }
    return null;
}
项目:spring-cloud-dataflow    文件:AbstractStreamCommands.java   
protected Map<String, String> getDeploymentProperties(@CliOption(key = {
        PROPERTIES_OPTION }, help = "the properties for this deployment") String deploymentProperties,
        @CliOption(key = {
                PROPERTIES_FILE_OPTION }, help = "the properties for this deployment (as a File)") File propertiesFile,
        int which) throws IOException {
    Map<String, String> propertiesToUse;
    switch (which) {
    case 0:
        propertiesToUse = DeploymentPropertiesUtils.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 = DeploymentPropertiesUtils.convert(props);
        break;
    case -1: // Neither option specified
        propertiesToUse = new HashMap<>(1);
        break;
    default:
        throw new AssertionError();
    }
    return propertiesToUse;
}
项目:spring-cloud-dataflow    文件: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));
        }
    }
}
项目:photogallery    文件:ApplicationConfig.java   
@Bean
public static PropertySourcesPlaceholderConfigurer properties() {
    PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer = new PropertySourcesPlaceholderConfigurer();
    YamlPropertiesFactoryBean yaml = new YamlPropertiesFactoryBean();
    yaml.setResources(new ClassPathResource("persistence.yml"));
    propertySourcesPlaceholderConfigurer.setProperties(yaml.getObject());
    return propertySourcesPlaceholderConfigurer;
}
项目:photogallery    文件:WebMvcConfig.java   
@Bean
public static PropertySourcesPlaceholderConfigurer properties() {
    PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer = new PropertySourcesPlaceholderConfigurer();
    YamlPropertiesFactoryBean yaml = new YamlPropertiesFactoryBean();
    yaml.setResources(new ClassPathResource("application.yml"));
    propertySourcesPlaceholderConfigurer.setProperties(yaml.getObject());
    return propertySourcesPlaceholderConfigurer;
}
项目:brooklyn-tosca    文件:Alien4CloudSpringContext.java   
public static ApplicationContext newApplicationContext(ManagementContext mgmt, ResourceLoader resourceLoader) throws Exception {
    log.info("Loading Alien4Cloud platform...");
    // TODO if ES cannot find a config file, it will hang waiting for peers; should warn if does not complete in 1m
    try {
        Stopwatch s = Stopwatch.createStarted();

        AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();

        if (null != resourceLoader) {
            ctx.setResourceLoader(resourceLoader);
        }

        // messy, but seems we must manually load the properties before loading the beans; otherwise we get e.g.
        // Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'directories.alien' in string value "${directories.alien}/plugins"
        final YamlPropertiesFactoryBean yamlPropertiesFactoryBean = AlienBrooklynYamlPropertiesFactoryBeanFactory.get(mgmt, ctx);
        if (yamlPropertiesFactoryBean == null) {
            throw new IllegalStateException("Could not load configuration for A4C. Expected either a value for ConfigKey " +
                    AlienBrooklynYamlPropertiesFactoryBeanFactory.ALIEN_CONFIG_FILE.getName() + " or for a resource named " +
                    AlienYamlPropertiesFactoryBeanFactory.ALIEN_CONFIGURATION_YAML + " to be available.");
        }


        ctx.getEnvironment().getPropertySources().addFirst(new PropertiesPropertySource("user",
                yamlPropertiesFactoryBean.getObject()));
        ctx.getBeanFactory().registerSingleton("brooklynManagementContext", mgmt);

        ctx.register(Alien4CloudSpringContext.class, Alien4CloudSpringConfig.class);
        ctx.refresh();
        ctx.registerShutdownHook();
        log.info("Finished loading Alien4Cloud platform (" + Duration.of(s) + ")");
        return ctx;

    } catch (Throwable t) {
        log.warn("Errors loading Alien4Cloud platform (rethrowing): " + t, t);
        throw Exceptions.propagate(t);
    }
}
项目:nyla    文件:PostItApp.java   
@Bean
public static PropertySourcesPlaceholderConfigurer properties() {
  PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer = new PropertySourcesPlaceholderConfigurer();
  YamlPropertiesFactoryBean yaml = new YamlPropertiesFactoryBean();
  yaml.setResources(new ClassPathResource("application.yml"));
  propertySourcesPlaceholderConfigurer.setProperties(yaml.getObject());
  return propertySourcesPlaceholderConfigurer;
}
项目:editor-de-servicos    文件:WebMVCConfig.java   
@Bean
public YamlPropertiesFactoryBean yamlPropertiesFactoryBean() throws IOException {
    YamlPropertiesFactoryBean permissoes = new YamlPropertiesFactoryBean();
    permissoes.setResources(new ClassPathResource("permissoes.yaml"));
    permissoes.afterPropertiesSet();
    return permissoes;
}
项目:spring-cloud-config    文件: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);
        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;
}
项目:Spring-Security-Third-Edition    文件:JavaConfig.java   
@Bean
public static YamlPropertiesFactoryBean yamlPropertiesFactoryBean() {
    YamlPropertiesFactoryBean yaml = new YamlPropertiesFactoryBean();
    yaml.setResources(new ClassPathResource("application.yml"));
    return yaml;
}
项目:Spring-Security-Third-Edition    文件:JavaConfig.java   
@Bean
public static YamlPropertiesFactoryBean yamlPropertiesFactoryBean() {
    YamlPropertiesFactoryBean yaml = new YamlPropertiesFactoryBean();
    yaml.setResources(new ClassPathResource("application.yml"));
    return yaml;
}
项目:Spring-Security-Third-Edition    文件:JavaConfig.java   
@Bean
public static YamlPropertiesFactoryBean yamlPropertiesFactoryBean() {
    YamlPropertiesFactoryBean yaml = new YamlPropertiesFactoryBean();
    yaml.setResources(new ClassPathResource("application.yml"));
    return yaml;
}
项目:Spring-Security-Third-Edition    文件:JavaConfig.java   
@Bean
public static YamlPropertiesFactoryBean yamlPropertiesFactoryBean() {
    YamlPropertiesFactoryBean yaml = new YamlPropertiesFactoryBean();
    yaml.setResources(new ClassPathResource("application.yml"));
    return yaml;
}
项目:Spring-Security-Third-Edition    文件:JavaConfig.java   
@Bean
public static YamlPropertiesFactoryBean yamlPropertiesFactoryBean() {
    YamlPropertiesFactoryBean yaml = new YamlPropertiesFactoryBean();
    yaml.setResources(new ClassPathResource("application.yml"));
    return yaml;
}
项目:Spring-Security-Third-Edition    文件:JavaConfig.java   
@Bean
public static YamlPropertiesFactoryBean yamlPropertiesFactoryBean() {
    YamlPropertiesFactoryBean yaml = new YamlPropertiesFactoryBean();
    yaml.setResources(new ClassPathResource("application.yml"));
    return yaml;
}
项目:Spring-Security-Third-Edition    文件:JavaConfig.java   
@Bean
public static YamlPropertiesFactoryBean yamlPropertiesFactoryBean() {
    YamlPropertiesFactoryBean yaml = new YamlPropertiesFactoryBean();
    yaml.setResources(new ClassPathResource("application.yml"));
    return yaml;
}
项目:Spring-Security-Third-Edition    文件:JavaConfig.java   
@Bean
public static YamlPropertiesFactoryBean yamlPropertiesFactoryBean() {
    YamlPropertiesFactoryBean yaml = new YamlPropertiesFactoryBean();
    yaml.setResources(new ClassPathResource("application.yml"));
    return yaml;
}
项目:raptor    文件:BaseApplication.java   
@Bean
public static PropertySourcesPlaceholderConfigurer properties() {
    PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer = new PropertySourcesPlaceholderConfigurer();

    propertySourcesPlaceholderConfigurer.setIgnoreResourceNotFound(false);

    ArrayList<String> defaultSources = new ArrayList(Arrays.asList("raptor.yml", appName + ".yml"));

    if (additionalConfigNames != null && !additionalConfigNames.isEmpty()) {
        defaultSources.addAll(additionalConfigNames);
    }

    ArrayList<String> sources = new ArrayList(defaultSources);

    if (developmentMode) {
        defaultSources.forEach((source) -> {
            sources.add(source.replace(".yml", ".dev.yml"));
        });
    }

    try {
        String envPath = System.getenv("CONFIG_BASEPATH");
        if (envPath != null && envPath.isEmpty()) {
            log.debug("Using CONFIG_BASEPATH={}", envPath);
            basepath = envPath;
        }
    } catch (Exception e) {
        log.warn("Failed to read environment variable CONFIG_BASEPATH: %s", e.getMessage());
    }

    log.debug("Configuration path {}", basepath);

    List<Resource> resources = sources.stream()
            .filter(f -> new File(basepath + f).exists())
            .map(f -> new FileSystemResource(basepath + f))
            .collect(Collectors.toList());

    log.debug("Configuration sources: {}", resources.toString());

    if (resources.isEmpty()) {
        throw new RuntimeException("Cannot find a loadable property file in: " + basepath);
    }

    YamlPropertiesFactoryBean yaml = new YamlPropertiesFactoryBean();
    yaml.setResources(resources.toArray(new Resource[]{}));

    propertySourcesPlaceholderConfigurer.setProperties(yaml.getObject());
    return propertySourcesPlaceholderConfigurer;
}
项目:sw360rest    文件:AccessTokenPrinter.java   
public static Properties getPropertiesFromApplicationYml() {
    YamlPropertiesFactoryBean yamlPropertiesFactoryBean = new YamlPropertiesFactoryBean();
    yamlPropertiesFactoryBean.setResources(new ClassPathResource("application.yml"));
    return yamlPropertiesFactoryBean.getObject();
}
项目:spring-cloud-stream-app-starters    文件:AwsIntegrationTestStackRule.java   
@Override
protected void before() throws Throwable {
    try {
        String awsCredentialsDir = System.getProperty("aws.credentials.path");
        File awsCredentialsFile = new File(awsCredentialsDir, "aws.credentials.properties");
        Properties awsCredentials = new Properties();
        awsCredentials.load(new FileReader(awsCredentialsFile));
        String accessKey = awsCredentials.getProperty("cloud.aws.credentials.accessKey");
        String secretKey = awsCredentials.getProperty("cloud.aws.credentials.secretKey");
        this.cloudFormation = new AmazonCloudFormationClient(new BasicAWSCredentials(accessKey, secretKey));

        YamlPropertiesFactoryBean yamlPropertiesFactoryBean = new YamlPropertiesFactoryBean();
        yamlPropertiesFactoryBean.setResources(new ClassPathResource("application.yml"));
        Properties applicationProperties = yamlPropertiesFactoryBean.getObject();

        this.stackName = applicationProperties.getProperty("cloud.aws.stack.name");

        after();

        ClassPathResource stackTemplate = new ClassPathResource("AwsIntegrationTestTemplate.json");
        String templateBody = FileCopyUtils.copyToString(new InputStreamReader(stackTemplate.getInputStream()));

        this.cloudFormation.createStack(
                new CreateStackRequest()
                        .withTemplateBody(templateBody)
                        .withOnFailure(OnFailure.DELETE)
                        .withStackName(this.stackName));

        waitForCompletion();

        System.setProperty("cloud.aws.credentials.accessKey", accessKey);
        System.setProperty("cloud.aws.credentials.secretKey", secretKey);
    }
    catch (Exception e) {
        if (!(e instanceof AssumptionViolatedException)) {
            Assume.assumeTrue("Can't perform AWS integration test because of: " + e.getMessage(), false);
        }
        else {
            throw e;
        }
    }
}
项目:egd-web    文件:ArgumentResolver.java   
public static Properties secretProperties(String profile) {
    YamlPropertiesFactoryBean yaml = new YamlPropertiesFactoryBean();
    yaml.setResources(new ClassPathResource("config/application-" + profile + "-secret.yml"));
    yaml.afterPropertiesSet();
    return yaml.getObject();
}
项目:editor-de-servicos    文件:GerenciadorPermissoes.java   
@Autowired
public GerenciadorPermissoes(YamlPropertiesFactoryBean properties) {
    this.properties = properties;
}
项目:editor-de-servicos    文件:GerenciadorPermissoesTest.java   
private static YamlPropertiesFactoryBean loadProperty() {
    YamlPropertiesFactoryBean permissoes = new YamlPropertiesFactoryBean();
    permissoes.setResources(new ClassPathResource("permissoesTest.yaml"));
    permissoes.afterPropertiesSet();
    return permissoes;
}
项目:orchestrator    文件:Alien4CloudConfig.java   
@Bean(name = { "alienconfig", "elasticsearchConfig" })
public YamlPropertiesFactoryBean alienConfig(ResourceLoader resourceLoader) {
  return AlienYamlPropertiesFactoryBeanFactory.get(resourceLoader);
}