Build configs.properties in src directory
Backup.host = 192.168.1.6==pwd
To create a static class:
PackageCom.ly.jxc.util;Importjava.io.IOException;ImportJava.util.HashMap;ImportJava.util.Map;Importjava.util.Properties;ImportOrg.springframework.beans.factory.config.PropertyPlaceholderConfigurer;ImportOrg.springframework.core.io.ClassPathResource;ImportOrg.springframework.core.io.Resource;Importorg.springframework.core.io.support.PropertiesLoaderUtils;/*** Configuration file Read class *@authorYQ * 2014-09-29*/ Public classConfigsextendsPropertyplaceholderconfigurer {Private StaticMap<string, object>Ctxpropertiesmap; protected Static voidload () {Resource Resource=NewClasspathresource ("/config.properties"); Properties props; Try{Props=propertiesloaderutils.loadproperties (Resource); Ctxpropertiesmap=NewHashmap<string, object>(); for(Object key:props.keySet ()) {String keystr=key.tostring (); String value=Props.getproperty (KEYSTR); Ctxpropertiesmap.put (keystr, value); } } Catch(IOException e) {//TODO auto-generated Catch blockE.printstacktrace (); }} /*** return int with default value *@paramname *@return */ Public Static intGetintvalue (String name,intDefaultValue) { if(Ctxpropertiesmap = =NULL||ctxpropertiesmap.isempty ()) load (); if(Ctxpropertiesmap.get (name) = =NULL) returnDefaultValue; returninteger.parseint (String) ctxpropertiesmap.get (name)); } /*** Return int *@paramname *@return */ Public Static intGetintvalue (String name) {if(Ctxpropertiesmap = =NULL||ctxpropertiesmap.isempty ()) load (); if(Ctxpropertiesmap.get (name) = =NULL) return0; returninteger.parseint (String) ctxpropertiesmap.get (name)); } /*** Return String *@paramname *@return */ Public Staticstring GetValue (string name) {if(Ctxpropertiesmap = =NULL||ctxpropertiesmap.isempty ()) load (); return(String) ctxpropertiesmap.get (name); } }
Then configure the static class (see my other article http://www.cnblogs.com/yqweber/p/3992513.html) to be able to use the page directly to take the value.
Read the properties file in spring