1. Properties文件
message.properties:
dmwdp.app.name=${dmwdp.app.name}
2. 本机OS Properties文件
dmwdp-commons.properties:
dmwdp.app.name=DMWDP
3. 读取类
public class MessagePropertiesReader {
private static final Logger LOGGER = Logger.getLogger(MessagePropertiesReader.class);
private static Properties props = new Properties();
private MessagePropertiesReader() {
}
static {
try {
final InputStream inoutStream =
MessagePropertiesReader.class.getResourceAsStream("/message.properties");
props.load(inoutStream);
} catch (Exception e) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("MessagePropertiesReader error", e);
}
}
}
/**
* 根据key返回对应的value
* @param key properties文件中对应的key
* @return key对应的value
* @author FDC
*/
public static String getMessageByKey(String key) {
return props.getProperty(key);
}
public static void main(String args[]) {
System.out.println(MessagePropertiesReader.getMessageByKey("dmwdp.app.name"));
}
}