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/