Component inside a fragment never activated
Asked Answered
C

1

4

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)
Chinch answered 21/12, 2011 at 16:12 Comment(1)
i also have a bnd.bdn which specify componets in fragment . do i have to specify anything more for fragment compnents in bnd file ?Chinch
D
7

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

Dissatisfactory answered 21/12, 2011 at 18:3 Comment(2)
thanks for your reply . I think am not doing right design by keeping service component in a fragment .Chinch
It would be helpful to understand why you're trying to do this in a fragment to begin with. Fragments have a very limited set of use-cases so perhaps it would be better to post a question describing the original problem that led you down the road of using them; maybe we can find a better solution.Gonagle

© 2022 - 2024 — McMap. All rights reserved.