More references: http://kingxss.iteye.com/blog/1880681
Propertiesfactorybean is a direct implementation class for Propertiesloadersupport, a factory bean that is designed to manage properties files, which is by default a single instance,
And Propertyplaceholderconfigurer is to solve the problem of the properties file placeholder, also realize the Propertiesloadersupport class.
In Java code, it is common to use @value annotations to refer to properties of a property file.
When using Propertyplaceholderconfigurer, the @Value expression is @Value (value= "${properties key}").
When using Propertiesfactorybean, we can also read the values of properties objects using @value, @Value usage is @Value (value= "#{configproperties[" Properties Key ']} ')
<bean id=" configproperties "class=" org.springframework.beans.factory.config. Propertiesfactorybean "> <property name=" Locations "> <list> ;value>classpath:/config/jdbc.properties</value> <VALUE>CLASSPATH:/CONFIG/BASE.PROPERTIES&L t;/value> </list> </property> </bean> <!--properties file read into--> <
Bean id= "Propertyconfigurer" class= "Org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" > <property name= "Properties" ref= "Configproperties"/> </bean>
<!-- <util:properties/> tags can only load a file, when more than one property file needs to be loaded, use more than the label --> <util:properties id= "remotesettings" location= "file:/opt/demo/config/ Demo-remote.properties " /> <!-- <util:properties/ The implementation class for the > tag is propertiesfactorybean, directly using the bean configuration of the class, setting its locations property to one that loads multiple configuration files as above --> <bean id= "Settings" class= " Org.springframework.beans.factory.config.PropertiesFactoryBean "> <property name= "Locations" > <list> <value >file:/opt/rms/config/rms-mq.properties</value> <value>file :/opt/rms/config/rms-env.properties</value> </list> </property> &nbSp </bean>
After spring 2.5, you can use the
<context:property-placeholder location= "Classpath:com/foo/jdbc.properties"/>
Its essence is to register a propertyplaceholderconfigurer (before 3.1) or Propertysourcesplaceholderconfigurer (after 3.1)
@Value (value= "${profit.rate.csprofitrate}")
double rate = 0.9;
@Value (value= "#{configproperties[' Profit.rate.csProfitRate ']}")
double rate2 = 0.9;