首页 > 编程语言 > 详细

Spring Properties 读取 PropertyPlaceholderConfigurer

时间:2017-12-21 11:39:38      阅读:232      评论:0      收藏:0      [点我收藏+]
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

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!