装载配置文件
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:database.properties</value>
<value>classpath:redis.properties</value>
</list>
</property>
</bean>
同时加入全局变量
public class CustomPropertyPlaceholderConfigurer extends PropertyPlaceholderConfigurer {
protected void processProperties(ConfigurableListableBeanFactory beanFactory,
java.util.Properties props)throws BeansException {
super.processProperties(beanFactory, props);
for (Object key : props.keySet()) {
String keyStr = key.toString();
String value = props.getProperty(keyStr);
GLOBAL_CONFIG_PROPERTIES.put(keyStr, value);
}
}
}
<bean id="propertyConfigurer"
class="CustomPropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:database.properties</value>
<value>classpath:redis.properties</value>
</list>
</property>
</bean>