overview

Origin

Setting

As is well known, the widely used configuration file Properties in Java has a major flaw: it does not support Chinese characters. Every time it is used, if you want to store Chinese characters, you must use IDE-related plugins to convert them to Unicode symbols, which are unreadable in the command line (imagine how painful it is to modify the configuration file after deploying it on a server).

As a result, many frameworks have gradually abandoned Properties files and turned to XML configuration files (such as Hibernate and early versions of Spring). However, the verbose configuration method of XML is unbearable. Hence, Setting was born.

Props

The second problem with Properties is that it is very inconvenient to read, requiring us to write long code for the load operation:

properties = new Properties();
try {
 Class clazz = Demo1.class;
 InputStream inputestream = clazz.getResourceAsStream("db.properties");
 properties.load(inputestream);
} catch (IOException e) {
 //ignore
}

Props, on the other hand, greatly simplifies this:

Props props = new Props("db.properties");

Considering that Properties is still widely used, the Props class was encapsulated to address compatibility issues.