osgi系列之— .properties文件读取
2015-10-21 15:06
232 查看
bundle A 加载osgi context中所有bundle的
application文件夹下.properties的键值对方法
每个bundle独有一个classLoader,在运行环境中,所以考虑将所有bundle的properties中的属性键值对,放置在全局Util类中,供程序使用。具体方法:
private static String CONFIG_PATH = "configuration"; private static String FilePattern = "*.properties"; public void init() throws Exception { Bundle[] bds = bundle.getBundleContext().getBundles(); for (Bundle b : bds) { Enumeration<URL> e = b.findEntries(CONFIG_PATH, FilePattern, true); if (e != null) { while (e.hasMoreElements()) { URL url = e.nextElement(); if (url != null) { InputStream in = url.openStream(); try { properties.load(in); } finally { in.close(); } } } } } }
在启动osgi framework时,Activator的start()方法中,调用上述方法,实现加载所有的properties。
Activator.context = bundleContext; Bundle bundle = context.getBundle(); String bundleName = bundle.getSymbolicName(); FrameworkPropertyHolder propertyHolder = new FrameworkPropertyHolder(); propertyHolder.setBundle(bundle); propertyHolder.init();
osgi继承spring后,启动spring容器时,在配置文件中,需要解析通配符${xxx.name}.
需要实现spring的PropertyPlaceholderConfigurer类,下一篇再做具体介绍。
相关文章推荐
- linux程序设计学习笔记
- CentOS Mysql自动备份 .txt
- org.apache.jasper.JasperException: PWC6345: There is an error in invoking javac. A full JDK (not ju
- Hadoop2.2内存调优
- 有趣的库:pipe(类似linux | 管道)库
- 旧文备份:rtlinux安装手册
- hibernate.properties
- hibernate.properties
- 轻松实现将网页“分享到”多个网站空间的悬浮按钮框
- OpenCV实现USM锐化与测试
- 从uboot传参数给linux驱动
- Linux vi命令
- 6.gitbash同步vs工程
- hadoop2.x集群的安装
- 使用安装在linux端的loadgenerator,在controller加载并发人数受限的问题解决
- linux c fopen修改已经存在的文件
- 使用corosync+pacemaker构建高可用集群
- centos6.5安装php5.6版本
- Eclipse部署不成功的问题(部署到tomcat中,只有个空文件夹)
- 在linux中数据库备份遇到的问题