Context:property-placeholder import multiple standalone. Properties Profiles in spring?
The spring container uses the discovery mechanism of reflection scanning, which has a org.springframework.beans.factory.config.PropertyPlaceholderConfigurer in the detection of spring containers. The bean will stop scanning the remaining propertyplaceholderconfigurer (Spring 3.1 has used propertysourcesplaceholderconfigurer instead Propertyplaceholderconfigurer).
In other words, the spring container allows only a maximum of one propertyplaceholderconfigurer (or <context:property-placeholder/>) to be defined, The rest will be ignored by spring (in fact, if spring provides a warning).
For example, if the A and B modules are running separately, because the spring container has only one propertyplaceholderconfigurer, the properties file will be loaded and replaced normally. If the A and B two modules are integrated and run, there are two propertyplaceholderconfigurer beans in the spring container, and then look who first who is behind, the first reservation, after the neglect! As a result, only one property file is loaded, resulting in an issue where property substitution cannot be performed correctly.
How to solve it?
Wildcard resolution
<context:property-placeholder location= "Classpath*:conf/conf*.properties"/>
_________________________________________________________________________________________
Spring's properties Analysis
Source: http://www.cnblogs.com/beiyeren/p/3488871.html
You typically use Propertyplaceholderconfigurer to replace placeholders, such as:
<bean class= "Org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" > <property Name= "Locations" > <value>classpath:com/foo/strategy.properties</value> </property > <property name= "Properties" > <value>custom.strategy.class=com.foo.defaultstrategy</ Value> </property></bean>
After spring 2.5, you can use the
<context:property-placeholder location= "Classpath:com/foo/jdbc.properties"/>
Its essence is to register a propertyplaceholderconfigurer (before 3.1) or Propertysourcesplaceholderconfigurer (after 3.1)
TIP:
Propertyplaceholderconfigurer built-in feature is very rich, if it does not find the XXX key defined in ${xxx}, it will also go to the JVM System Properties (System.getproperty () ) and Environment variables (system.getenv ()). By enabling the Systempropertiesmode and Searchsystemenvironment properties, developers can control this behavior.
and propertysourcesplaceholderconfigurer on this basis will be better with environment and Propertysource.
In addition, the following points need to be noted
1. Shouldgenerateid returns true in the parent class of Propertyplaceholderbeandefinitionparser, that is, by default a unique name is generated for each bean, if two <context are used: Property-placeholder registers two propertysourcesplaceholderconfigurer beans, so it is not overwritten (and the bean if the same name is behind the bean definition covers the front);
2, Propertysourcesplaceholderconfigurer Essence is a beanfactorypostprocessor,spring implementation when the bean is found to implement the ordered, then executed in order; default unordered ;
3, at this time if the <context:property-placeholder add order attribute, then will be reflected in order, the lower the value of the higher priority is the earlier execution;
Like what
<context:property-placeholder order= "2" location= "Classpath*:conf/conf_a.properties"/>
<context:property-placeholder order= "1" location= "Classpath*:conf/conf_b.properties"/>
The order= ' 1 ' is scanned first, if not scanned order= ' 2 '
4, by default, Ignore-unresolvable, that is, if you do not find the case throws an exception. Default false: The exception is thrown;
<context:property-placeholder location= "Classpath*:conf/conf_a.properties" ignore-unresolvable= "false"/>
Spring Context:property-placeholder Import multiple standalone. Properties Profiles