Spring XML using resource files for placeholder configuration does not take effect

The problem that has been bothering before about using spring to read resource files in XML files and replacing them with ${} placeholders is now finally understood.

  1. If there are multiple XML files that need to be replaced by resource file placeholders, they must be loaded first at the head of each XML file .
  2. When injecting resource files into multiple XML files, configure order and set ignoreUnresolvablePlaceholders=true

The specific configuration is as follows:

 

<!-- Import external data source configuration information must be loaded in the XML header -->
    <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <!-- No ignore properties that cannot be found . -->
        <property name="ignoreResourceNotFound" value="true" /> 
        <!-- ignoreUnresolvablePlaceholders is whether to ignore unresolvable Placeholders.
            If multiple PropertyPlaceholderConfigurers are configured, set it to true -->
        <property name= "ignoreUnresolvablePlaceholders" value="true" />
        <!-- The order attribute represents its loading order. The smaller the value, the first to load -->
        <property name="order" value="2" />
        <property name="locations ">
            <list>
                <value>classpath:runMode/db.properties</value>
            </list>
        </property>
    </bean>
 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326517979&siteId=291194637