javaosgiosgi-fragment

Component inside a fragment never activated


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)

Solution

  • 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