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.
- 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 .
- 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>