List of usage examples for org.springframework.beans.factory.config YamlPropertiesFactoryBean afterPropertiesSet
@Override public void afterPropertiesSet()
From source file:io.spring.initializr.metadata.InitializrMetadataBuilderTests.java
private static Properties loadProperties(Resource resource) { YamlPropertiesFactoryBean yamlFactory = new YamlPropertiesFactoryBean(); yamlFactory.setResources(resource);//from www . j a v a 2 s .c o m yamlFactory.afterPropertiesSet(); return yamlFactory.getObject(); }
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)); }//from w ww . ja v a 2 s.com } }
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/* w w w . java 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 ww .j a va2s. co m } }
From source file:org.springframework.cloud.dataflow.shell.command.StreamCommands.java
@CliCommand(value = DEPLOY_STREAM, help = "Deploy a previously created stream") public String deployStream(@CliOption(key = { "", "name" }, help = "the name of the stream to deploy", mandatory = true/*, optionContext = "existing-stream undeployed disable-string-converter"*/) String name, @CliOption(key = {//from www . j ava 2 s . com PROPERTIES_OPTION }, help = "the properties for this deployment", mandatory = false) String properties, @CliOption(key = { PROPERTIES_FILE_OPTION }, help = "the properties for this deployment (as a File)", mandatory = false) File propertiesFile) throws IOException { int which = Assertions.atMostOneOf(PROPERTIES_OPTION, properties, PROPERTIES_FILE_OPTION, propertiesFile); Map<String, String> propertiesToUse; switch (which) { case 0: propertiesToUse = DeploymentPropertiesUtils.parse(properties); 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 = Collections.<String, String>emptyMap(); break; default: throw new AssertionError(); } streamOperations().deploy(name, propertiesToUse); return String.format("Deployment request has been sent for stream '%s'", name); }
From source file:org.springframework.cloud.deployer.admin.shell.command.ApplicationCommands.java
@CliCommand(value = DEPLOY_APPLICATION, help = "Deploy a previously created application") public String deployApplication( @CliOption(key = { "", "name" }, help = "the name of the application to deploy", mandatory = true) String name, @CliOption(key = {/*www.j a v a2 s .c o m*/ PROPERTIES_OPTION }, help = "the properties for this deployment", mandatory = false) String properties, @CliOption(key = { PROPERTIES_FILE_OPTION }, help = "the properties for this deployment (as a File)", mandatory = false) File propertiesFile) throws IOException { int which = Assertions.atMostOneOf(PROPERTIES_OPTION, properties, PROPERTIES_FILE_OPTION, propertiesFile); Map<String, String> propertiesToUse; switch (which) { case 0: propertiesToUse = DeploymentPropertiesUtils.parse(properties); 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 = Collections.<String, String>emptyMap(); break; default: throw new AssertionError(); } applicationOperations().deploy(name, propertiesToUse); return String.format("Deployment request has been sent for application '%s'", name); }