【问题标题】:OSGI Bundle bean delcaration issueOSGI Bundle bean 声明问题
【发布时间】:2017-11-15 06:09:12
【问题描述】:

我是 OSGI 蓝图定义的新手,我正在尝试完成以下任务:

Bundle 1 : 包含 Bean1(其中有一个 Bean2 注入)都在 blueprint1 中声明

Bundle 2 : 在它的 blueprint2 中,我想使用 Bean1(不声明 Bean2)

结果: Bundle 2 失败:缺少对 Bean2 的依赖,这是有道理的,因为 Bundle 2 没有添加 Bean2,但我不想让它在这个 bundle 中可见,它在 Blueprint1 中包含一些复杂的配置(而且我没有不想在 Blueprint2 中重新复制整个内容) 我希望在 Bundle1 中创建它并在 Bundle2 中使用它

问题: 有什么方法可以从 Bundle 2 获得这种访问权限(bean1 应该就像其他 bundle 使用的服务)?如果没有,有没有其他方法可以做?

感谢您的帮助。

根据要求,在我的蓝图下方:

蓝图 1:

`

<?xml version="1.0"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" ... >
   <bean id="bean1" class="Bean1" />
   <bean id="bean2" class="Bean2" />
</blueprint>

`

蓝图 2:

`

<?xml version="1.0"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" ... >
   <bean id="bean1" class="Bean1" />
</blueprint>

`

豆 1:

public class Bean1 {

  @BeanInject("bean2")
  Bean2 bean2;

  .... 

}

蓝图 2 失败

【问题讨论】:

  • 目前还不完全清楚您要做什么。您说 Bundle2 由于缺少依赖项 Bean2 而失败。 Bean2 在哪里声明?你能发布你的蓝图 XML 文件吗?

标签: java osgi-bundle blueprint-osgi


【解决方案1】:

下面是我的解决方案:

blueprint 中的 Bean 声明将始终采用本地 bundle 上下文,这应该标识此 bean 中使用的所有依赖项,因此如果不声明 Bean2,就无法在 blueprint2 中调用 bean1。

解决方法是使用一个服务,在Blueprint1中将bean1声明为服务,在Blueprint2中作为引用使用,那么就不需要定义任何依赖了。

这里描述的详细解决方案:Service OSGI

【讨论】:

    猜你喜欢
    • 2011-05-21
    • 2011-10-06
    • 2013-01-12
    • 2017-06-11
    • 2014-04-27
    • 2013-11-19
    • 2014-01-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多