【问题标题】:Refreshing OSGI application-context刷新 OSGI 应用程序上下文
【发布时间】: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


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-01-03
    • 2011-05-07
    • 1970-01-01
    • 2023-03-28
    • 1970-01-01
    • 2017-01-16
    • 1970-01-01
    • 2018-08-23
    相关资源
    最近更新 更多