【发布时间】:2018-07-11 13:40:34
【问题描述】:
我正在开发 OSGI 应用程序,我需要在运行时刷新我的 application-context.xml。
我想用
String ctxPath = ....
ApplicationContext ctx = new FileSystemXmlApplicationContext(ctxPath);
((ConfigurableApplicationContext)ctx).refresh();
问题是 - 我找不到通往我的 application-context.xml 的路径(它在 OSGI 包中)。我知道的唯一方法是使用
InputStream inputStream = new BufferedInputStream(this.getClass().getClassLoader().getResourceAsStream("/application-context.xml"));
但我无法从InputStream 获取路径。任何想法如何使这项工作?
【问题讨论】:
-
您的捆绑包目前看起来如何?你在 OSGi 中使用 spring-dm 启动 spring 吗?
-
你所说的“你的捆绑包是什么样子”是什么意思?不,我没有使用 spring-dm
-
那么你如何在你的bundle中开始spring呢?使用激活器?
-
afaik osgi 捆绑资源不能用作文件系统上的文件。您可能想使用
ClassPathXmlApplicationContext而不是FileSystemXmlApplicationContext;并提供路径“/application-context.xml”。
标签: osgi osgi-bundle applicationcontext