<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:db.properties"/>
<!--指定外部属性文件的编码格式-->
<property name="fileEncoding" value="UTF-8"></property>
</bean>
<context:property-placeholder location="classpath:db.properties"/>
<context:property-placeholder location="classpath:db.properties,classpath:db.properties"/><bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfi
gurer">
<property name="locations">
<list>
<!-- 这里支持多种寻址方式:classpath和file -->
<value>classpath:/opt/demo/config/demo-db.properties</value>
<!-- 推荐使用file的方式引入,这样可以将配置和代码分离 -->
<value>file:/opt/demo/config/demo-mq.properties</value>
<value>file:/opt/demo/config/demo-remote.properties</value>
</list>
</property>
</bean>
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfi
gurer">
<property name="locations">
<list>
<!-- 这里支持多种寻址方式:classpath和file -->
<value>classpath:/opt/demo/config/demo-db.properties</value>
<!-- 推荐使用file的方式引入,这样可以将配置和代码分离 -->
<value>file:/opt/demo/config/demo-mq.properties</value>
<value>file:/opt/demo/config/demo-remote.properties</value>
</list>
</property>
</bean>
本文介绍了Spring框架中PropertyPlaceholderConfigurer的使用方法,包括如何通过不同的路径加载配置文件(如classpath和file路径),并展示了如何在Spring配置文件中引用这些外部属性文件。
1008

被折叠的 条评论
为什么被折叠?



