读配置文件property文件

时间:2022-08-28 20:04:06


import java.io.IOException;
import java.util.Properties;

import org.springframework.core.io.support.PropertiesLoaderUtils;

/**
* Description: 读取配置文件http地址配置<br>
*/
public class ConfigFileUtils {

/**
* 读取authconfig.properties
*
* @param nodeName
* @return
*/
public static String getAuthconfig(String nodeName) {
String configName = "application.properties";
String result = pubReadConfig(configName, nodeName);
if (result == null) {
result = pubReadConfig("prop/" + configName, nodeName);
}
return result;
}

/**
* 通用读取方法
*
* @param configName
* @param nodeName
* @return
*/
public static String pubReadConfig(String configName, String nodeName) {
Properties props = new Properties();
while (true) {
try {
props = PropertiesLoaderUtils.loadAllProperties(configName);
return (String) props.get(nodeName);
} catch (IOException e) {
System.out.println(e.getMessage());
}
}
}
}