Spring uses multiple propertyplaceholderconfigurer configurations

Source: Internet
Author: User

In spring, propertyplaceholderconfigurer is used to parse the value of the Java properties property file and replace the attribute value during spring configuration. Next, let's gradually go deep into its configuration.

The basic usage is as follows: (1)

<Bean id = "propertypolicerforanalysis" class = "org. springframework. Beans. Factory. config. propertyplaceholderconfigurer">
<Property name = "location">
<Value> classpath:/spring/include/dbquery. properties </value>
</Property>
</Bean>

Classpath references the file writing method under the src directory.

When multiple properties files exist, the configuration requires the use of locations: (2)

<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>
</List>
</Property>
</Bean>

Next, we will use multiple propertyplaceholderconfigurer for decentralized configuration to integrate multiple scattered properties files under multiple projects. The configuration is as follows: (3)

<Bean id = "propertypolicerforproject1" class = "org. springframework. Beans. Factory. config. propertyplaceholderpolicer">
<Property name = "order" value = "1"/>
<Property name = "ignoreunresolvableplaceholders" value = "true"/>
<Property name = "location">
<Value> classpath:/spring/include/dbquery. properties </value>
</Property>
</Bean>

<Bean id = "propertypolicerforproject2" class = "org. springframework. Beans. Factory. config. propertyplaceholderpolicer">
<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>

The Order attribute indicates the loading order, while the ignoreunresolvableplaceholders indicates whether to ignore unresolvable placeholder. If multiple propertyplaceholderregistrers are configured, the value must be set to true.

Zookeeper to: http://wjl198408.blog.163.com/blog/static/2540214720105724845630/

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.