Detailed explanation of the context:property-placeholder element in spring

In the spring-context.xml configuration, read the configuration file and we will configure it like this,

    <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">

        <property name="locations">

            <list>

                <value>classpath:conf-${spring.profiles.active}.properties</value>

            </list>

        </property>

        <property name="fileEncoding" value="utf-8"/>

    </bean>

As everyone knows, there is another tag that is easily ignored, <context:property-placeholder/>

To simplify the use of PropertyPlaceholderConfigurer, Spring provides the <context:property-placeholder/> element.

An example configuration is given below. When enabled, the developer does not need to configure the PropertyPlaceholderConfigurer object.

 

<context:property-placeholder location="userinfo.properties"/> 

It is very feature rich, if it does not find the xxx key defined in ${xxx}, it will also look in the JVM system properties (System.getProperty()) and environment variables (System.getenv()).

 

Developers can control this behavior by enabling the systemPropertiesMode and searchSystemEnvironment properties.

Guess you like

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