读取properties中value

来源:互联网 发布:网络架构培训 编辑:程序博客网 时间:2024/05/16 06:36
import java.text.MessageFormat;import java.util.Properties;import org.springframework.beans.BeansException;import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;public class ExpandPropertyPlaceholderConfigurer extendsPropertyPlaceholderConfigurer {private static Properties myProperties=new Properties();@Overrideprotected void processProperties(ConfigurableListableBeanFactory beanFactoryToProcess,Properties props) throws BeansException {// TODO Auto-generated method stubsuper.processProperties(beanFactoryToProcess, props);myProperties.putAll(props);}/** * 获取配置 * @param key * @return */public static String getProperty(String key){return myProperties.getProperty(key);}/** * 获取配置 * @param key * @param param 要替换的值 * @return */public static String getProperty(String key,Object[] param){return MessageFormat.format(getProperty(key), param);}}<beanclass="com.sf.customer.service.core.util.ExpandPropertyPlaceholderConfigurer"><property name="ignoreResourceNotFound" value="true" /><property name="locations"><list><value>classpath:jdbc.properties</value><value>classpath:system.properties</value><value>classpath:message.properties</value></list></property></bean>