A
First, we'll start with the spring configuration file. Defines a class that specifically reads the properties file.
Cases:
1 class= "Org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" >2 < Property Name= "Locations" >3 <list>4 <value>classpath*:jdbc.properties </value>5 <!--If you have more than one profile, just continue adding it here--6 </list>7 </property>8 </bean>
Why use locations here (there is also a location)
In general, there may be more than one configuration file in our project.
Even if there is only one, the new additions in the future, just add a value tag below,
Without having to re-modify too much.
(ii) Use of Context:property-placeholder in spring
Cases:
<context:property-placeholder location= "Classpath:data/mybatis.properties"/>
However, multiple properties files cannot be loaded, and the spring container uses a discovery mechanism for reflection scanning, in which a spring container is detected Org.springframework.beans.factory.config.PropertyPlaceholderConfigurer's 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) to be defined, and 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.
Workaround:
1 <!--load all configuration Files--2 <context:property-placeholder location= "classpath*:d ata/*.properties"/ >3 <!--can also be loaded in multiple directories--4
Spring configuration loads multiple properties files