在JAVA文件中使用Spring读取的property
来源:互联网 发布:秀图软件 编辑:程序博客网 时间:2024/06/10 19:57
一、自定义初始化的类继承org.springframework.beans.factory.config.PropertyPlaceholderConfigurer
重写processProperties(...)方法把读取的properties依次读取放到系统的缓存中。对外提供getProperty(String name)方法作为java代码中需要读取property时调用的方法.
代码如下:
public class CustomizedPropertyPlaceholderConfigurer extendsPropertyPlaceholderConfigurer {private static Map<String, Object> propertiesMap = null;@Overrideprotected void processProperties(ConfigurableListableBeanFactory beanFactoryToProcess,Properties props) throws BeansException {super.processProperties(beanFactoryToProcess, props);propertiesMap = new HashMap<String, Object>();for(Object key:props.keySet()){String keyStr = ObjectUtils.toString(key);propertiesMap.put(keyStr, props.getProperty(keyStr));}}public static Object getPorperty(String name){return propertiesMap.get(name);}}
二、在spring配置文件中将参数初始化类配置为上面自定义的类
<bean id="propertyConfigurer" class="com.qiyuntian.store.base.utils.CustomizedPropertyPlaceholderConfigurer"> <property name="location"> <value>classpath:env.properties</value> </property> </bean>
这样就可以再java代码中读取,properties文件中的内容了。
0 0
- 在JAVA文件中使用Spring读取的property
- java中读取和写入property文件的方法
- spring中读取数据库的property配置文件
- java 读取property文件
- java 读取property文件
- java读取property文件
- java 读取 property 属性文件的代码
- spring mvc3读取property文件
- Spring boot 在Java文件中读取Resource下的文件
- Java读取操作Property文件
- java如何读取property文件
- spring中读取property的几种方式及解析
- Attached Property在Xaml中,使用Property Element的写法
- Spring中属性文件properties的读取与使用
- Spring中属性文件properties的读取与使用
- Spring中属性文件properties的读取与使用
- Spring中属性文件properties的读取与使用
- Spring中属性文件properties的读取与使用
- Pat(Advanced Level)Practice--1045(Favorite Color Stripe)
- Sun Grid Engine state meaning
- php计算代码执行时间
- 稀疏表达的人脸识别(Robust Face)实现
- HDOJ1057 A New Growth Industry 【模拟】
- 在JAVA文件中使用Spring读取的property
- HDOJ 2084 数塔
- 响应式web设计之CSS3 Media Queries
- mfc创建timer工程
- javascript中expression的用法
- C++ 类型转换归纳
- About@fant-face
- 指针高级运算总结
- nagios插件之监控RTTI返回情况(模拟坐席发起)