PropertyPlaceholderConfigurer ​​​​​​使用方法 

 

 

 

 

 

spring-plugins.xml文件中

      <!-- load properties -->
    <bean id="propertyConfigurer" class="com.rskj.core.util.PropertyPlaceholder">
        <property name="locations">
            <list>
                <value>classpath:config/*.properties</value>
            </list>
        </property>
    </bean>

 

其中com.rskj.core.util.PropertyPlaceholder对应为com.rskj.core.util包下的PropertyPlaceholder.java文件

 

package com.rskj.core.util;

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;

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);
        }
    }

    public static String getProperty(String name) {
        return propertyMap.get(name);
    }
}
 

 

 

使用:

String source_props = PropertyPlaceholder.getProperty("source");

相关文章:

  • 2022-12-23
  • 2021-11-28
  • 2022-12-23
  • 2021-08-18
  • 2021-09-03
  • 2022-12-23
  • 2021-12-13
猜你喜欢
  • 2022-02-02
  • 2022-01-07
  • 2022-12-23
  • 2021-08-11
  • 2021-12-30
相关资源
相似解决方案