User-defined configuration files
Userconfiguration.properties
Spring Bean Preparation
| <!--User defined configuration bean--> <!--If you pass in more than one, you can also configure the following <bean id= "userconfiguration" class= "util.configuration"; <property name= "locations"; <list <value>classpath:conf/ Userconfiguration.properties</value> </list </property> </bean> --> <!--use constructors to inject--> <bean id= " UserConfiguration "class=" util.configuration, <constructor-arg Value= "Classpath:conf/userconfiguration.properties"/> </bean> |
Implementation of the Util.configuration class
Package util;
Import Org.springframework.core.io.Resource; Import java.io.IOException; Import Java.io.InputStream; Import java.util.Properties;
public class Configuration { The hash Map properties Private Properties m_map = null;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///// Public configuration (Resource conffile) { Try { InputStream InputStream = Conffile.getinputstream ();
M_map = new Properties ();
M_map.load (InputStream); } catch (IOException E) { E.printstacktrace (); } }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///// public string GetValue (String strkey) { if (m_map! = null) Return M_map.getproperty (strkey); Else Return ""; } } |
The core of the entire technology is the use of-org.springframework.core.io.Resource
Read user-defined configuration files with spring