系统中需要加载多个Properties配置文件
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<!-- 将多个配置文件读取到容器中,交给Spring管理 -->
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<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>
<!-- 使用MQ中的配置 -->
<bean id="MQJndiTemplate" class="org.springframework.jndi.JndiTemplate">
<property name="environment">
<props>
<prop key="java.naming.factory.initial">${mq.java.naming.factory.initial}</prop>
<prop key="java.naming.provider.url">${mq.java.naming.provider.url}</prop>
<prop key="java.naming.security.principal">${mq.java.naming.security.principal}</prop>
<prop key="java.naming.security.credentials">${mq.java.naming.security.credentials}</prop>
<prop key="userName">${mq.java.naming.security.principal}</prop>
<prop key="password">${mq.java.naming.security.credentials}</prop>
</props>
</property>
</bean>
</beans>