1.
In the spring configuration file, configure the properties file that you want to read
<Beanclass= "Org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> < Propertyname= "Systempropertiesmodename"value= "System_properties_mode_override" /> < Propertyname= "fileencoding"value= "UTF-8" /> < Propertyname= "Locations"> <List> <value>Classpath:jdbc.properties</value> <value>Classpath:config.properties</value> </List> </ Property></Bean>
2.
Parameters in the Config.properties:
Pay.url=http://www.test.com/pay.htm
3.
ImportOrg.springframework.beans.factory.annotation.Value;Importorg.springframework.stereotype.Component; @Component Public classConfiguration {@Value (Value= "${pay.url}") PrivateString Payurl; PublicString Getpayurl () {returnPayurl; } Public voidSetpayurl (String payurl) { This. Payurl =Payurl; }}
The @Value (value = "${pay.url:123}") represents the pay.url default value of 123
Spring uses annotations to read parameters within the properties file