原文:https://www.cnblogs.com/hafiz/p/5876243.html
归纳:
-
<context:property-placeholder location="classpath:config.properties" ignore-unresolvable="true"/> 示例: @Value("#{name}") private String name;
-
<bean id="prop" class="org.springframework.beans.factory.config.PropertiesFactoryBean"> <!-- 这里是PropertiesFactoryBean类,它也有个locations属性,也是接收一个数组,跟上面一样 --> <property name="locations"> <array> <value>classpath:config.properties</value> </array> </property> </bean> 示例: @Value("#{prop.name}") private String name;
-
<util:properties id="propertiesReader" location="classpath:config.properties"/> 这种方式创建了一个bean,以bean的方式来使用,示例: @Value("#{propertiesReader[name]}") private String name;