Java Code Examples for org.springframework.core.io.support.PropertiesLoaderUtils#loadProperties()

The following examples show how to use org.springframework.core.io.support.PropertiesLoaderUtils#loadProperties() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XMLContentLoader.java    From syncope with Apache License 2.0 6 votes vote down vote up
private void createIndexes(final String domain, final DataSource dataSource) throws IOException {
    LOG.debug("[{}] Creating indexes", domain);

    JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);

    Properties indexes = PropertiesLoaderUtils.loadProperties(indexesXML.getResource());
    indexes.stringPropertyNames().stream().sorted().forEachOrdered(idx -> {
        LOG.debug("[{}] Creating index {}", domain, indexes.get(idx).toString());
        try {
            jdbcTemplate.execute(indexes.getProperty(idx));
        } catch (DataAccessException e) {
            LOG.error("[{}] Could not create index", domain, e);
        }
    });

    LOG.debug("Indexes created");
}
 
Example 2
Source File: InitPropConfigFactory.java    From mPaaS with Apache License 2.0 6 votes vote down vote up
/**
 * 配置文件信息获取
 *
 * @return
 */
@Override
public Map<String, Object> defaultConfig() {
    Map<String, Object> rtnMap = new HashMap<>(1);
    try {
        ClassLoader classLoader = this.getClass().getClassLoader();
        Enumeration<URL> urls = (classLoader != null ?
                classLoader.getResources(getPropFilePath()) :
                ClassLoader.getSystemResources(getPropFilePath()));
        while (urls.hasMoreElements()) {
            URL url = urls.nextElement();
            UrlResource resource = new UrlResource(url);
            Properties properties = PropertiesLoaderUtils.loadProperties(resource);
            for (Map.Entry<?, ?> entry : properties.entrySet()) {
                rtnMap.put((String) entry.getKey(), entry.getValue());
            }
        }
    } catch (IOException e) {
        log.error("加载初始配置错误.", e);
    }
    return rtnMap;
}
 
Example 3
Source File: I18nUtil.java    From zuihou-admin-cloud with Apache License 2.0 6 votes vote down vote up
public static Properties loadI18nProp() {
    if (prop != null) {
        return prop;
    }
    try {
        // build i18n prop
        String i18n = XxlJobAdminConfig.getAdminConfig().getI18n();
        i18n = StringUtils.isNotBlank(i18n) ? ("_" + i18n) : i18n;
        String i18nFile = MessageFormat.format("i18n/message{0}.properties", i18n);

        // load prop
        Resource resource = new ClassPathResource(i18nFile);
        EncodedResource encodedResource = new EncodedResource(resource, "UTF-8");
        prop = PropertiesLoaderUtils.loadProperties(encodedResource);
    } catch (IOException e) {
        logger.error(e.getMessage(), e);
    }
    return prop;
}
 
Example 4
Source File: I18nUtil.java    From open-capacity-platform with Apache License 2.0 6 votes vote down vote up
public static Properties loadI18nProp(){
    if (prop != null) {
        return prop;
    }
    try {
        // build i18n prop
        String i18nFile = "i18n/message.properties";

        // load prop
        Resource resource = new ClassPathResource(i18nFile);
        EncodedResource encodedResource = new EncodedResource(resource,"UTF-8");
        prop = PropertiesLoaderUtils.loadProperties(encodedResource);
    } catch (IOException e) {
        logger.error(e.getMessage(), e);
    }
    return prop;
}
 
Example 5
Source File: I18nUtil.java    From xmfcn-spring-cloud with Apache License 2.0 6 votes vote down vote up
public static Properties loadI18nProp(){
    if (prop != null) {
        return prop;
    }
    try {
        // build i18n prop
        String i18n = XxlJobAdminConfig.getAdminConfig().getI18n();
        i18n = StringUtils.isNotBlank(i18n)?("_"+i18n):i18n;
        String i18nFile = MessageFormat.format("i18n/message{0}.properties", i18n);

        // load prop
        Resource resource = new ClassPathResource(i18nFile);
        EncodedResource encodedResource = new EncodedResource(resource,"UTF-8");
        prop = PropertiesLoaderUtils.loadProperties(encodedResource);
    } catch (IOException e) {
        logger.error(e.getMessage(), e);
    }
    return prop;
}
 
Example 6
Source File: Config.java    From awesome-delay-queue with MIT License 6 votes vote down vote up
@Bean
public AwesomeURL awesomeUrl() throws IOException {
    String configPath = storage+".properties";
    Resource resource = new ClassPathResource(configPath);
    Properties props = PropertiesLoaderUtils.loadProperties(resource);
    Set<String> keySet = props.stringPropertyNames();
    String host = props.getProperty("host");
    int port = Integer.parseInt(props.getProperty("port"));
    String username = props.getProperty("username");
    String password = props.getProperty("password");
    Map<String,String> paramMap = new HashMap<>();
    for (String key:keySet){
        paramMap.put(key, (String) props.get(key));
    }
    AwesomeURL awesomeURL = new AwesomeURL(storage,username,password,host,port,null,paramMap);
    return awesomeURL;
}
 
Example 7
Source File: PropertiesUtil.java    From DataLink with Apache License 2.0 6 votes vote down vote up
/**
 * 获取properties文件内容
 *
 * @param propertiesPath :绝对路径
 * @return
 */
public static Properties getProperties(String propertiesPath) throws IOException {

    Properties resultProperties = propertiesMap.get(propertiesPath);

    if (resultProperties == null) {
        Resource resource = new PathResource(propertiesPath);
        try {
            resultProperties = PropertiesLoaderUtils.loadProperties(resource);
        } catch (FileNotFoundException e) {
            resultProperties = null;
        }

        if (resultProperties != null)
            propertiesMap.put(propertiesPath, resultProperties);
    }

    return resultProperties;
}
 
Example 8
Source File: I18nUtil.java    From zuihou-admin-boot with Apache License 2.0 6 votes vote down vote up
public static Properties loadI18nProp() {
    if (prop != null) {
        return prop;
    }
    try {
        // build i18n prop
        String i18n = XxlJobAdminConfig.getAdminConfig().getI18n();
        i18n = StringUtils.isNotBlank(i18n) ? ("_" + i18n) : i18n;
        String i18nFile = MessageFormat.format("i18n/message{0}.properties", i18n);

        // load prop
        Resource resource = new ClassPathResource(i18nFile);
        EncodedResource encodedResource = new EncodedResource(resource, "UTF-8");
        prop = PropertiesLoaderUtils.loadProperties(encodedResource);
    } catch (IOException e) {
        logger.error(e.getMessage(), e);
    }
    return prop;
}
 
Example 9
Source File: BinderFactoryAutoConfiguration.java    From spring-cloud-stream with Apache License 2.0 6 votes vote down vote up
static Collection<BinderType> parseBinderConfigurations(ClassLoader classLoader,
		Resource resource) throws IOException, ClassNotFoundException {
	Properties properties = PropertiesLoaderUtils.loadProperties(resource);
	Collection<BinderType> parsedBinderConfigurations = new ArrayList<>();
	for (Map.Entry<?, ?> entry : properties.entrySet()) {
		String binderType = (String) entry.getKey();
		String[] binderConfigurationClassNames = StringUtils
				.commaDelimitedListToStringArray((String) entry.getValue());
		Class<?>[] binderConfigurationClasses = new Class[binderConfigurationClassNames.length];
		int i = 0;
		for (String binderConfigurationClassName : binderConfigurationClassNames) {
			binderConfigurationClasses[i++] = ClassUtils
					.forName(binderConfigurationClassName, classLoader);
		}
		parsedBinderConfigurations
				.add(new BinderType(binderType, binderConfigurationClasses));
	}
	return parsedBinderConfigurations;
}
 
Example 10
Source File: AesPreferencesConfigurer.java    From rebuild with GNU General Public License v3.0 5 votes vote down vote up
/**
    * 从安装文件加载配置
    *
    * @return
    * @see #INSTALL_FILE
    */
private Properties fromInstallFile() {
       File file = SysConfiguration.getFileOfData(INSTALL_FILE);
       if (file.exists()) {
           try {
               return PropertiesLoaderUtils.loadProperties(new FileSystemResource(file));
           } catch (IOException e) {
               throw new SetupException(e);
           }
       }
       return new Properties();
   }
 
Example 11
Source File: PigResourcesGenerator.java    From pig with MIT License 5 votes vote down vote up
/**
 * 获取配置文件
 *
 * @return 配置Props
 */
private static Properties getProperties() {
    // 读取配置文件
    Resource resource = new ClassPathResource("/config/application.properties");
    Properties props = new Properties();
    try {
        props = PropertiesLoaderUtils.loadProperties(resource);
    } catch (IOException e) {
        e.printStackTrace();
    }
    return props;
}
 
Example 12
Source File: ProjectService.java    From citrus-admin with Apache License 2.0 5 votes vote down vote up
/**
 * Reads default Citrus project property file for active project.
 * @return properties loaded or empty properties if nothing is found
 */
public Properties getProjectProperties() {
    File projectProperties = fileBrowserService.findFileInPath(new File(project.getProjectHome()), "citrus.properties", true);

    try {
        if (projectProperties != null) {
            return PropertiesLoaderUtils.loadProperties(new FileSystemResource(projectProperties));
        }
    } catch (IOException e) {
        log.warn("Unable to read default Citrus project properties from file resource", e);
    }

    return new Properties();
}
 
Example 13
Source File: CCPropertySourceLoader.java    From jeesuite-config with Apache License 2.0 5 votes vote down vote up
private Properties loadProperties(String name, Resource resource) throws IOException{
	Properties properties = null;
	if(name.contains("properties")){
		properties = PropertiesLoaderUtils.loadProperties(resource);
	}else{
		YamlPropertiesFactoryBean bean = new YamlPropertiesFactoryBean();
		bean.setResources(resource);
		properties = bean.getObject();
	}
	return properties;
}
 
Example 14
Source File: ManagementEnvironmentCustomizer.java    From Moss with Apache License 2.0 5 votes vote down vote up
@Override
public void customize(ConfigurableEnvironment env) {
    try {
        Properties props;
        ClassPathResource resource = new ClassPathResource(DEFAULT_PROPERTY);
        props = PropertiesLoaderUtils.loadProperties(resource);
        props.put(SPRINGBOOT_MANAGEMENT_PORT_KEY, getManagementPort(env));
        env.getPropertySources().addLast(new PropertiesPropertySource("managementProperties", props));
    } catch (IOException e) {
        logger.error("Failed to load " + DEFAULT_PROPERTY);
    }
}
 
Example 15
Source File: ManagementEnvironmentCustomizer.java    From Moss with Apache License 2.0 5 votes vote down vote up
@Override
public void customize(ConfigurableEnvironment env) {
    try {
        Properties props;
        ClassPathResource resource = new ClassPathResource(DEFAULT_PROPERTY);
        props = PropertiesLoaderUtils.loadProperties(resource);
        props.put(SPRINGBOOT_MANAGEMENT_PORT_KEY, getManagementPort(env));
        env.getPropertySources().addLast(new PropertiesPropertySource("managementProperties", props));
    } catch (IOException e) {
        logger.error("Failed to load " + DEFAULT_PROPERTY);
    }
}
 
Example 16
Source File: ApplicationProperties.java    From wangmarket with Apache License 2.0 5 votes vote down vote up
public ApplicationProperties() {
	try {
           Resource resource = new ClassPathResource("/application.properties");//
           properties = PropertiesLoaderUtils.loadProperties(resource);
       } catch (IOException e) {
           e.printStackTrace();
       }
}
 
Example 17
Source File: PropertiesUtil.java    From open-capacity-platform with Apache License 2.0 5 votes vote down vote up
public static String getString(String key) {
	Properties prop = null;
	try {
		Resource resource = new ClassPathResource(file_name);
		EncodedResource encodedResource = new EncodedResource(resource,"UTF-8");
		prop = PropertiesLoaderUtils.loadProperties(encodedResource);
	} catch (IOException e) {
		logger.error(e.getMessage(), e);
	}
	if (prop!=null) {
		return prop.getProperty(key);
	}
	return null;
}
 
Example 18
Source File: EventConfigInit.java    From MicroCommunity with Apache License 2.0 2 votes vote down vote up
/**
 * 加载文件
 * @param location
 * @param filename
 * @param
 */
private  static Properties load(String location,String filename) throws Exception{
    Properties properties = PropertiesLoaderUtils.loadProperties(new ClassPathResource(location+filename));
    return properties;
}
 
Example 19
Source File: SystemStartLoadBusinessConfigure.java    From MicroCommunity with Apache License 2.0 2 votes vote down vote up
/**
 * 加载文件
 * @param location
 * @param filename
 * @param
 */
private static  Properties load(String location,String filename) throws Exception{
    Properties properties = PropertiesLoaderUtils.loadProperties(new ClassPathResource(location+filename));
    return properties;
}
 
Example 20
Source File: SystemStartUpInit.java    From MicroCommunity with Apache License 2.0 2 votes vote down vote up
/**
 * 加载文件
 * @param location
 * @param filename
 * @param
 */
private Properties load(String location,String filename) throws Exception{
    Properties properties = PropertiesLoaderUtils.loadProperties(new ClassPathResource(location+filename));
    return properties;
}