commons-configuration的使用
各独立相关的配置放在一个单独配置文件中,整个应用由一个统一的配置装配文件global-config.xml,然后统一个Configuration类实的例来获取各种配置参数 the
ConfigurationFactory
class:
ConfigurationFactory factory = new ConfigurationFactory("config.xml"); Configuration config = factory.getConfiguration();
The config.xml
file used in the example above is a configuration descriptor,
it specifies the Configuration objects to load.
Here is an example of descriptor:
<configuration> <system/> <properties fileName="application.properties"/> </configuration>
What this says is that we are loading up all system properties,
as well as the propertiesfile
application.properties
. The order of precedence is first to last.So in the above example,
if a property is not found in the system properties, it'll be searched
in the properties file. This allows you to set up default values in a properties file, and override them with the system properties.
config.xml中格模块文件的配置顺序很重要,在前一配置中已找到配置参数值就不会再在后一文件中查找了
reference
0 Comments:
Post a Comment
<< Home