OSGI Bundle bean 声明问题
OSGI Bundle bean delcaration issue
我是 OSGI 蓝图定义的新手,我正在努力完成以下任务:
Bundle 1 : 包含所有在 blueprint1
中声明的 Bean1(具有 Bean2 注入)
Bundle 2 : 在它的 blueprint2 中,我想使用 Bean1(不声明 Bean2)
结果:
Bundle 2 失败:缺少对 Bean2 的依赖,这是有道理的,因为 Bundle 2 没有添加 Bean2,但我不想让它在这个包中可见,它在 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 失败
下面是我的解决方案:
蓝图中的 Bean 声明将始终采用本地 bundle 上下文,这个应该标识此 bean 中使用的所有依赖项,因此在不声明 Bean2 的情况下无法在蓝图 2 中调用 bean1。
解决方案是使用服务,在Blueprint1中将bean1声明为服务,在Blueprint2中将其作为引用使用,此时无需定义任何依赖。
此处描述了详细的解决方案:Service OSGI
我是 OSGI 蓝图定义的新手,我正在努力完成以下任务:
Bundle 1 : 包含所有在 blueprint1
中声明的 Bean1(具有 Bean2 注入)Bundle 2 : 在它的 blueprint2 中,我想使用 Bean1(不声明 Bean2)
结果: Bundle 2 失败:缺少对 Bean2 的依赖,这是有道理的,因为 Bundle 2 没有添加 Bean2,但我不想让它在这个包中可见,它在 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 失败
下面是我的解决方案:
蓝图中的 Bean 声明将始终采用本地 bundle 上下文,这个应该标识此 bean 中使用的所有依赖项,因此在不声明 Bean2 的情况下无法在蓝图 2 中调用 bean1。
解决方案是使用服务,在Blueprint1中将bean1声明为服务,在Blueprint2中将其作为引用使用,此时无需定义任何依赖。
此处描述了详细的解决方案:Service OSGI