审查视图

src/main/java/com/framework/util/PropertiesLoader.java 1.9 KB
fujinghui authored
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
package com.framework.util;


import java.io.InputStream;
import java.util.Properties;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


/**
 * @description roperties属性文件加载
 * @author gerry.zhang
 * @date 2014-5-29
 * @version 1.0
 *
 */
public class PropertiesLoader {
	
	private static final Logger logger = LoggerFactory.getLogger(PropertiesLoader.class); 
	
	private static final String CONFIG_FILE = "/config.properties";
23 24

	private static final String REDIS_FILE = "/redis.properties";
25 26

	private static final String LOGIN_FILE = "/openRemoteLogin.properties";
fujinghui authored
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
	
	/**
	 * 配置文件properties获取value
	 * @param key
	 * @param propertyFile 注意classpath下文件以"/"开始
	 * @return
	 */
	public static String get(String key){
		Properties properties = loadProperty("/application.properties");
		return (String) properties.get(key);
	}
	
	
	/**
	 * load properties文件
	 * @param propertyFile
	 * @return
	 */
	public static Properties loadProperty(String propertyFile){
		InputStream in=PropertiesLoader.class.getResourceAsStream(propertyFile); 
		Properties properties = new Properties();
		try{
			properties.load(in);
		}catch(Exception e){
			logger.error("解析文件失败:文件名={}", propertyFile, e);
		}
		return properties;
	}
	
	
	public static String getConfig(String key) {
		Properties properties = PropertiesLoader.loadProperty(CONFIG_FILE);
		return properties.getProperty(key);
	}
62 63 64 65 66
	public static String getRedis(String key) {
		Properties properties = PropertiesLoader.loadProperty(REDIS_FILE);
		return properties.getProperty(key);
	}
fujinghui authored
67
68 69 70 71 72 73
	public static String getLogin(String key) {
		Properties properties = PropertiesLoader.loadProperty(LOGIN_FILE);
		return properties.getProperty(key);
	}

fujinghui authored
74 75 76 77 78 79 80 81 82 83
	public static String get(String key,String propertyFile){
		Properties properties = loadProperty(propertyFile);
		return (String) properties.get(key);
	}
	
	
	
	 

}