Spring loads multiple properties at the same time

java method of loading properties file

http://blog.csdn.net/u011063151/article/details/51888640

spring xml load properties file

https://www.cnblogs.com/shanheyongmu/p/5806872.html

Need to load multiple properties at the same time, there is basically no reference for the above, re-written one

<!-- 属性文件获取 -->
    <bean id="propertyConfigurer" class="com.shiro.utils.ExtPropertyPlaceholderConfigurer">  
        <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
		<property name="ignoreResourceNotFound" value="true" />
		<property name="locations">
			<list>
				<value>classpath:jdbc.properties</value>
				<value>classpath*:ha_redis.properties</value>
			</list>
		</property>
    </bean> 
The specific implementation of the bean is as follows

package com.shiro.utils;

import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;

/**
 * 扩展属性文件读取
 * 
 * @author 
 *
 */
public class ExtPropertyPlaceholderConfigurer extends PropertyPlaceholderConfigurer {

	private static Map<String, Object> ctxPropertiesMap;

	@Override
	protected void processProperties(ConfigurableListableBeanFactory beanFactoryToProcess, Properties props)
			throws BeansException {
		super.processProperties(beanFactoryToProcess, props);
		ctxPropertiesMap = new HashMap<String, Object>();
		for (Object key : props.keySet()) {
			String keyStr = key.toString();
			String value = props.getProperty(keyStr);
			ctxPropertiesMap.put(keyStr, value);
		}
	}

	public Object getContextProperty(String name) {
		return ctxPropertiesMap.get(name);
	}
}

So that you can reference multiple properties at the same time
Published 64 original articles · Like9 · Visit 110,000+

Guess you like

Origin blog.csdn.net/eadela/article/details/78794510