片段中的组件从未激活 [英] Component inside a fragment never activated

查看:108
本文介绍了片段中的组件从未激活的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用OSGi声明式服务在片段内创建组件时,该组件没有被激活,但是主机捆绑包中的组件被激活了. 我想念什么吗?我的片段具有用于主机捆绑包符号名称的正确的meta-inf文件条目.

When I create a component inside a fragment using OSGi Declarative Service way this component is not getting activated but my components in host bundle gets activated. Am I missing something? My fragment has proper meta-inf file entry for host bundle symbolic name.

我以这种方式声明一个伴侣

I declare a componet in this way

@Component(immediate = true)

推荐答案

由于从不启动捆绑包片段,因此永远不会激活其中的已解析声明式服务组件.该规范特别指出,片段中的Service-Component标头(将注释转换为标头)将被忽略.

Because bundle fragments are never started, only resolved, declarative services components in them are never activated. The specification specifically states that Service-Component headers (which is what the annotation gets converted to) in fragments are ignored.

您可以使声明性服务适用于片段,但是只能通过从主机中的Service-Component标头引用片段中的XML文件来进行.不幸的是,让主机包知道片段中的内容可能与您追求的架构模式相反.我什至不确定使用SCR注释是否可以实现这种安排.一种选择是使用蓝图从片段中声明式注册服务,这确实有效.在 http://aries.apache.org/documentation/tutorials/blueprinthelloworldtutorial中有一个蓝图教程.html .

You can make declarative services work for fragments, but only by referencing a XML file in the fragment from a Service-Component header in the host. Having the host bundle know about what's in the fragment is probably the reverse of the architectural pattern you were after, unfortunately. I'm not even sure if such an arrangement would be possible using the SCR annotations. One option is to use blueprint to declaratively register services from fragments, which does work. There's a blueprint tutorial available at http://aries.apache.org/documentation/tutorials/blueprinthelloworldtutorial.html.

-

正在使用的企业OSGi:www.manning .com/cummins

这篇关于片段中的组件从未激活的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆