Component inside a fragment never activated

不想你离开。 提交于 2019-11-30 09:02:38

问题


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)

回答1:


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.

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.

--

Enterprise OSGi in Action: www.manning.com/cummins



来源:https://stackoverflow.com/questions/8592860/component-inside-a-fragment-never-activated

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!