码迷,mamicode.com
首页 > 其他好文 > 详细

读取配置文件 PropertyPlaceholderConfigurer 的配置与使用

时间:2015-08-17 16:53:49      阅读:94      评论:0      收藏:0      [点我收藏+]

标签:

public class SpringPropertyConfigurer extends PropertyPlaceholderConfigurer {  
      
    private static Map<String, String> ctxPropertiesMap;  
  
    @Override  
    protected void processProperties(ConfigurableListableBeanFactory beanFactory,  
            Properties props)throws BeansException {  
  
        super.processProperties(beanFactory, props);  
       
        ctxPropertiesMap = new HashMap<String, String>();  
        for (Object key : props.keySet()) {  
            String keyStr = key.toString();  
            String value = props.getProperty(keyStr);  
            ctxPropertiesMap.put(keyStr, value);  
        }  
    }  
  
    //static method for accessing context properties  
    public static String getContextProperty(String name) {  
        return ctxPropertiesMap.get(name);  
    }  
}

 

配置文件:

<!-- 加载PROPERTY配置文件 -->
    <bean id="propertySource" class="com.mediaforce.news.api.utils.SpringPropertyConfigurer">
        <property name="order" value="2" />
        <property name="ignoreUnresolvablePlaceholders" value="true" />
        <property name="fileEncoding">
            <value>UTF-8</value>
        </property>
        <property name="locations">
            <list>
                <value>classpath:message.properties</value>
                <value>classpath:sysconfig.properties</value>
            </list>
        </property>
    </bean>

 

读取配置文件 PropertyPlaceholderConfigurer 的配置与使用

标签:

原文地址:http://www.cnblogs.com/amei0/p/4736791.html

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