There are multiple PropertyPlaceholderConfigurer or <context:property-placeholder>
For example, I have two xml config file and they are loaded at same time in the web.xml.
1 <context-param>
2 <param-name>contextConfigLocation</param-name>
3 <param-value>
4 WEB-INF/config/spring/dao.xml,
5 WEB-INF/config/spring/service.xml
6 </param-value>
7 </context-param>
Or,
In one module's config xml import other module's config xml:
1 <import resource="classpath:/META-INF/spring/dao.xml" />
2 <import resource="classpath:/META-INF/spring/service.xml" />
2 <import resource="classpath:/META-INF/spring/service.xml" />
1 <!-- dao.xml -->
2 <context:property-placeholder location="WEB-INF/config/db/dbConnect.properties" />
3
4 <!-- service.xml -->
5 <context:property-placeholder location="WEB-INF/config/dfs/service.properties" />
2 <context:property-placeholder location="WEB-INF/config/db/dbConnect.properties" />
3
4 <!-- service.xml -->
5 <context:property-placeholder location="WEB-INF/config/dfs/service.properties" />
If config like this, there must be "Could not resolve placeholder" exception.
We have to remember that, no matter we use multiple xml and load together, or use single xml.
IT IS NOT ALLOWED TO HAVE:
1 <context:property-placeholder location="XXX" />
2 <context:property-placeholder location="YYY" />
2 <context:property-placeholder location="YYY" />
The solution is:
In spring 3.0:
1 <context:property-placeholder location="xxx.properties" ignore-unresolvable="true" />
2 <context:property-placeholder location="yyy.properties" ignore-unresolvable="true" />
2 <context:property-placeholder location="yyy.properties" ignore-unresolvable="true" />
In each <context:property-placeholder> , put ignore-unresolvable="true"
Each <context:property-placeholder> need to be configured.
If any one miss this configuration, all of them will not work.
In spring 2.5:
<context:property-placeholder> does not have ignore-unresolvable attribute,it needs to be changed to PropertyPlaceholderConfigurer。
<context:property-placeholder location="xxx.properties" ignore-unresolvable="true" /> equals to:
1 <bean id="xxx" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
2 <property name="location" value="xxx.properties" />
3 <property name="ignoreUnresolvablePlaceholders" value="true" />
4 </bean>
2 <property name="location" value="xxx.properties" />
3 <property name="ignoreUnresolvablePlaceholders" value="true" />
4 </bean>
Just because of this, if you config multiple PropertyPlaceholderConfigurer, but missing ignoreUnresolvablePlaceholders, exception "Could not resolve placeholder" will be thrown.
No comments:
Post a Comment