Import Java. util. map; import Org. apache. commons. configuration. configurationexception; import Org. apache. commons. configuration. propertiesconfiguration; import Org. apache. commons. configuration. reloading. filechangedreloadingstrategy; import Org. apache. log4j. logger; /***** configuration file properties automatically loaded class * @ author lyh * @ version 2012-6-5 * @ see propertiesautoload * @ since */public class propertiesautoload {/*** log */private static final logger log = logger. getlogger (propertiesautoload. class);/*** Singleton */Private Static final propertiesautoload auto_load = new propertiesautoload ();/*** configuration */Private Static propertiesconfiguration propconfig; /*** automatically save */Private Static Boolean autosave = true; /* ** properties file path * @ Param propertiesfile * @ return * @ see */public static propertiesautoload getinstance (string propertiesfile) {// execute initialization Init (propertiesfile ); return auto_load;}/*** obtain the corresponding value based on the key * @ Param key * @ return * @ see */public object getvaluefrompropfile (string key) {return propconfig. getproperty (key);}/*** get the corresponding value array * @ Param key * @ return * @ see */Public String [] getarrayfrompropfile (string key) {return propconfig. getstringarray (key);}/*** set attribute * @ Param key * @ Param value * @ see */Public void setproperty (string key, string value) {propconfig. setproperty (Key, value);}/*** set attribute * @ Param map * @ see */Public void setproperty (Map <string, string> map) {for (string key: map. keyset () {propconfig. setproperty (Key, map. get (key) ;}}/*** constructor privatize */private propertiesautoload () {}/*** initialize * @ Param propertiesfile * @ see */Private Static void Init (string propertiesfile) {try {propconfig = new propertiesconfiguration (propertiesfile ); // automatically reload propconfig. setreloadingstrategy (New filechangedreloadingstrategy (); // automatically save propconfig. setautosave (autosave);} catch (configurationexception e) {log. error (E. getmessage () ;}}/*** test * @ Param ARGs * @ see */public static void main (string [] ARGs) {log.info (propertiesautoload. getinstance ("props/config/xx. properties "). getvaluefrompropfile ("pagesize "));}}