码迷,mamicode.com
首页 > 编程语言 > 详细

Spring Properties 读取 PropertyPlaceholderConfigurer

时间:2017-12-21 12:05:13      阅读:164      评论:0      收藏:0      [点我收藏+]

标签:spring properties 读取

PropertyPlaceholderConfigurer

@Service("propertyPlaceholder")
public class PropertyPlaceholder extends PropertyPlaceholderConfigurer {

    private static Map<String,String> propertyMap;

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

    //static method for accessing context properties
    public Object getProperty(String name) {
        return propertyMap.get(name);
    }
}

xml

        <bean class="com.lxzl.config.PropertyPlaceholder">
			<property name="location">
            	<value>classpath:config.properties</value>
	        </property>
        </bean>


Spring Properties 读取 PropertyPlaceholderConfigurer

标签:spring properties 读取

原文地址:http://blog.51cto.com/xinzhilian/2052823

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!