context配置
<bean id="configBean" class="com.xxx.common.util.CommonPropertyConfigurer">
<property name="location">
<value>classpath:idservice.${env}.${site}.properties</value>
</property>
</bean>
实现类
package xxx.common.frontend.common.util;
import java.util.Properties;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
/**
* @author Haber He (hhe5)
*
*/
public class CommonPropertyConfigurer extends PropertyPlaceholderConfigurer {
private static Properties properties;
@Override
protected void processProperties(ConfigurableListableBeanFactory beanFactory, Properties props) throws BeansException {
super.processProperties(beanFactory, props);
properties = props;
}
public static String getValue(String key) {
return properties.getProperty(key);
}
public static int getIntValue(String key) {
return Integer.parseInt(properties.getProperty(key));
}
public static boolean getBooleanValue(String key){
return Boolean.parseBoolean(properties.getProperty(key));
}
}
用法
CommonPropertyConfigurer.getValue("Cache-Control")