PropertiesLoaderUtils
来源:互联网 发布:北师珠网络教学 编辑:程序博客网 时间:2024/05/21 17:42
{
String result = "";
Resource resource = new ClassPathResource(resourcePaht);
try
{
Properties props = PropertiesLoaderUtils.loadProperties(resource);
result = props.getProperty(key);
} catch (IOException e)
{
e.printStackTrace();
}
return result;
}
private Properties getvaluebyProperty(ApplicationContext context) {
AbstractApplicationContext abstractContext = (AbstractApplicationContext) context;
Properties properties = new Properties();
try {
// get the names of BeanFactoryPostProcessor
String[] postProcessorNames = abstractContext.getBeanNamesForType(
PropertyPlaceholderConfigurer.class, true, true);
for (String ppName : postProcessorNames) {
System.out.println(ppName);
// get the specified BeanFactoryPostProcessor
PropertyPlaceholderConfigurer beanProcessor = abstractContext.getBean(ppName,
PropertyPlaceholderConfigurer.class);
// check whether the beanFactoryPostProcessor is
// instance of the PropertyResourceConfigurer
// if it is yes then do the process otherwise continue
if (beanProcessor instanceof PropertyResourceConfigurer) {
PropertyResourceConfigurer propertyResourceConfigurer = (PropertyResourceConfigurer) beanProcessor;
// get the method mergeProperties
// in class PropertiesLoaderSupport
Method mergeProperties = PropertiesLoaderSupport.class
.getDeclaredMethod("mergeProperties");
// get the props
mergeProperties.setAccessible(true);
Properties props = (Properties) mergeProperties
.invoke(propertyResourceConfigurer);
// get the method convertProperties
// in class PropertyResourceConfigurer
Method convertProperties = PropertyResourceConfigurer.class.getDeclaredMethod(
"convertProperties", Properties.class);
// convert properties
convertProperties.setAccessible(true);
convertProperties.invoke(propertyResourceConfigurer, props);
properties.putAll(props);
}
}
} catch (Exception e) {
throw new RuntimeException(e);
}
return properties;
}
- PropertiesLoaderUtils
- PropertiesLoaderUtils.loadAllProperties()
- ClassPathResource与PropertiesLoaderUtils
- spring 之 PropertiesLoaderUtils 获取文件属性用法
- 使用Spring PropertiesLoaderUtils读取properties属性文件
- vs在不同版本的opencv之间切换
- UVALIVE 7505 Hungry Game of Ants DP
- delphi:斑马打印机ZPL指令打印中文及二维码,补充说明
- XMLHttpRequest cannot load 跨域问题解决
- css技巧
- PropertiesLoaderUtils
- VS2010创建并使用DLL http://www.cnblogs.com/laogao/archive/2012/12/07/2806528.html
- JSP学习笔记二之JSP的语法和9大内置对象(上)
- Python学习资源
- 项目中第一次做图片上传和下载功能过程>>>
- 函数模板和类模板
- 002_Http之介绍
- Eclipse中同时打开多个Console
- PHP中如何判断一个字符串是否是合法的日期模式