Spring reads the use of the configuration file Propertyplaceholderconfigurer class

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.