首页 > 解决方案 > 刷新 OSGI 应用程序上下文

问题描述

我正在开发 OSGI 应用程序,我需要在运行时刷新我的 application-context.xml。

我想用

String ctxPath = ....
ApplicationContext ctx = new FileSystemXmlApplicationContext(ctxPath);
((ConfigurableApplicationContext)ctx).refresh();

问题是 - 我找不到获取 application-context.xml 路径的方法(它在 OSGI 包中)。我知道的唯一方法是使用 bundle 的内部文件

InputStream inputStream = new BufferedInputStream(this.getClass().getClassLoader().getResourceAsStream("/application-context.xml"));

但我无法从InputStream. 任何想法如何使这项工作?

标签: osgiosgi-bundleapplicationcontext

解决方案


我能想象的唯一方法是获取InputStream(你也可以Bundle.getEntry为那个),然后将文件保存在你知道路径的地方。我已经在几个应用程序中看到了这种方法,所以我认为它是正确的。


推荐阅读