Spring 将properties文件转为系统工具类
2015-10-22 19:01
519 查看
context配置
实现类
用法
<bean id="configBean" class="com.morningstar.productservices.search.ac.common.frontend.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")
相关文章推荐
- Java读取UTF-8格式txt文件第一行出现乱码——问号“?”及解决;Java读带有BOM的UTF-8文件乱码原因及解决方法
- Ford-Fulkerson算法 java实现
- Java集合类详解之例子
- NLPIR/ICTCLAS中文分词系统 java相关api文档总结
- 推荐几个高质量的博客
- Eclipse选中一个变量名,相同变量都变色显示设置
- Java实现经纬度格式转化
- Unsupported major.minor version 51.0错误
- java部分关键字
- Java反射学习和笔记——黑马训练营
- java 时间相关操作
- java,awt,中文方框,中文乱码
- 将Eclipse项目转化为Android项目,并且做到结构兼容
- 浅谈Java多线程编程中Boolean常量的同步问题
- java转义字符
- Java_BigDecimal类型比较大小
- Java集合框架之Collection学习和笔记——黑马训练营
- 深入解析Java编程中的boolean对象的运用
- Spring MVC异常处理详解
- eclipse中Maven运行时报错: -Dmaven.multiModuleProjectDirectory system propery is not set. Check $M2_HOME environment variable and mvn script match.