以下代碼沒有使用spring的工具類來獲取 config配置文件的數據
public class PropertiesUtil
{
/**
* 配置文件對象
*/
private static Properties props= new Properties();
static {
try
{
// myspring.properties 為配置文件所在的位置
props.load(PropertiesUtil.class.getClassLoader().getResourceAsStream("myspring.properties"));
}
catch (IOException e)
{
e.printStackTrace();
}
}
public static String getValue(String key)
{
return props.getProperty(key);
}
public static void main(String[] args)
{
// 獲取 myspring.base.package的value
System.out.println(getValue("myspring.base.package"));
}
}