web工程配置properties

 先创建*.properties文件

#openapi地址配置
openapiDir = openapi

 

 

在接口类中定义

public static String OPEN_API = "openapi";

static {
  InputStream is = null;
try {
  Properties pro = new Properties();
  is = CommomUtil.class.getResourceAsStream("/*.properties");
  pro.load(is);
  OPEN_API = pro.getProperty("openapiDir");
  APPKEY = pro.getProperty("APPKEY");
  LOGINKEY = pro.getProperty("LOGINKEY");
  is.close();

} catch (IOException e) {
  e.printStackTrace();
if (is != null) {
try {
  is.close();
} catch (IOException e1) {
  e1.printStackTrace();
}
}
}
}

 

就能获取配置文件的值

你可能感兴趣的:(web工程配置properties)