This article mainly introduces the use of the Propertyplaceholderconfigurer class, which is used in spring to read the configuration file and set the variables in the configuration file to the context and assign values.
One, here use the list tag to read the multi-properties file information into the Propertyplaceholderconfigurer class
<BeanID= "Propertyconfigurer"class= "Org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> < Propertyname= "Locations"> <List> <!--multiple addressing methods are supported here: Classpath and file - <value>Classpath:/opt/demo/config/demo-db.properties</value> <!--The introduction of file is recommended, so that the configuration and code can be separated - <value>File:/opt/demo/config/demo-mq.properties</value> <value>File:/opt/demo/config/demo-remote.properties</value> </List> </ Property> </Bean>
Second, you can read a multi-configuration file into the list, and then assign a reference to the list
<!--placing multiple profile locations in a list - <BeanID= "Propertyresources"class= "Java.util.ArrayList"> <Constructor-arg> <List> <!--multiple addressing methods are supported here: Classpath and file - <value>Classpath:/opt/demo/config/demo-db.properties</value> <!--The introduction of file is recommended, so that the configuration and code can be separated - <value>File:/opt/demo/config/demo-mq.properties</value> <value>File:/opt/demo/config/demo-remote.properties</value> </List> </Constructor-arg> </Bean> <!--read the configuration file into the container and give it to spring management - <BeanID= "Propertyconfigurer"class= "Org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> < Propertyname= "Locations"ref= "Propertyresources" /> </Bean>
Spring reads the use of the configuration file Propertyplaceholderconfigurer class