1.Spring frame, the Org.springframework.beans.factory.config.PropertyPlaceholderConfigurer class can have the. Properties (Key/value form ) file
Some dynamically set values (value), which are replaced with the value of the placeholder ($key $) in the XML.
The. properties file can customize some of the relevant parameters based on customer needs, and this design provides flexibility for the program.
2. In spring, you can use Propertyplaceholderconfigurer to add an external property file to an XML configuration file and, of course, to specify the encoding of an external file, such as:
<bean id= "Propertyconfigurer" class= "Org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" >
<property name= "Location" >
<value>conf/sqlmap/jdbc.properties</value>
</ property>
<property name= "fileencoding" >
<value>UTF-8</value>
</property >
</bean>
Of course, you can also introduce multiple property files, such as:
<bean id= "Propertyconfigurer" class= "Org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" >
<property name= "Locations" >
<list>
<value>/web-inf/mail.properties</value >
<value>classpath:conf/sqlmap/jdbc.properties</value>//pay attention to the two kinds of value of the notation
</list>
</property>
</bean>
The basic use of this method is:
XML code
<bean id= "Propertyconfigurerforanalysis" class= " Org.springframework.beans.factory.config.PropertyPlaceholderConfigurer ">
<property name=" Location " >
<value>classpath:/spring/include/dbQuery.properties</value>
</property>
<property name= "fileencoding" >
<value>UTF-8</value>
</property>
</ Bean>
The classpath is a reference to the SRC directory of the file.
When multiple properties files exist, the configuration will need to use locations:
XML code
<bean id= "Propertyconfigurer" class= "Org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" >
<property name= "Locations" >
<list>
<value>classpath:/spring/include/ Jdbc-parms.properties</value>
<value>classpath:/spring/include/base-config.properties</ value>
<value>classpath*:config/jdbc.properties</value>
</list>
</property >
</bean>
Next we need to use multiple propertyplaceholderconfigurer to distribute the configuration, to achieve the integration of multiple projects under a number of decentralized properties files, which are configured as follows
XML code
<bean id= "PropertyConfigurerForProject1" class= " Org.springframework.beans.factory.config.PropertyPlaceholderConfigurer ">
<property name=" Order "value= "1" />
<property name= "Ignoreunresolvableplaceholders" value= "true" />
<property Name = "Location" >
<value>classpath:/spring/include/dbQuery.properties</value>
</property >
</bean>
XML code
<bean id= "PropertyConfigurerForProject2" class= " Org.springframework.beans.factory.config.PropertyPlaceholderConfigurer ">
<property name=" Order "value= "2" />
<property name= "Ignoreunresolvableplaceholders" value= "true" />
<property Name = "Locations" >
<list>
<value>classpath:/spring/include/jdbc-parms.properties</value >
<value>classpath:/spring/include/base-config.properties</value>
</list>
</property>
</bean>
More Wonderful content: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/Java/