Could not resolve placeholder solution

When loading the properties file with spring configuration, a
Could not resolve placeholder error is reported.
After careful search, the reasons for the file path and file class tolerance are excluded, and after searching for relevant information, the "Could not resolve placeholder" is likely to be the reason for using multiple PropertyPlaceholderConfigurers or multiple <context:property-placeholder> or Multiple PropertyPlaceholderConfigurers are mixed with <context:property-placeholder>.
If the configuration is as follows, the above error will be reported, whether in multiple configuration files or in different files

quote
<context:property-placeholder location="WEB-INF/config/db/XX.properties" />  
<context:property-placeholder location="WEB-INF/config/dfs/XX.properties" /> 


Solution:
In Spring 3, it can be solved in the following way, adding ignore-unresolvable="true" attribute, note that it must be added

quote
<context:property-placeholder location="xxx.properties" ignore-unresolvable="true"  /> 
<context:property-placeholder location="yyy.properties" ignore-unresolvable="true" 
/> 


In Spring 2.5, <context:property-placeholder> does not have the ignore-unresolvable property, so PropertyPlaceholderConfigurer can be used instead. In fact, <context:property-placeholder location="xxx.properties" ignore-unresolvable="true" /> is equivalent to the following configuration

quote
<bean id="XX" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> 
    <property name="location" value="xxx.properties" /> 
    <property name="ignoreUnresolvablePlaceholders" value="true" />  
</bean> 


If the above error is reported in the system, you can find it like this: Search all files containing property-placeholder in the system to see if they contain the ignore-unresolvable property, and then search all files containing PropertyPlaceholderConfigurer in the system to see if they contain the ignoreUnresolvablePlaceholders property.

The above error is reported in the system today, because the ignoreUnresolvablePlaceholders property is not configured according to the PropertyPlaceholderConfigurer method, and the ignore-unresolvable property is included in the configuration according to the context:property-placeholder method.


Reference: http://blog.163.com/wf_shunqiziran/blog/static/176307209201282755010505/

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327057281&siteId=291194637