Search code examples
osgideclarative-services

OSGi DS: Omit unbind method with Felix SCR @Reference annotation


OSGi declarative services are explicitly allowed to have a bind method without a matching unbind method for a reference because "Once the component configuration is deactivated, SCR must discard all references to the component instance and component context associated with the activation."

I'm using the Apache Felix maven-scr-plugin to generate my service component XML from Java5 annotations. If I omit the "unbind" attribute from the @Reference annotation, then I get this failure:

[ERROR] @Reference: Missing method unbind for reference configuration at Java annotations in <classname>:<linenum>

Why is the SCR generator being so strict? Is there a way to tell it to tolerate an omitted unbind method? Perhaps I need to file a defect with Felix?

Of course, it would be easy to just add trivial unbind methods to my services but the spec says they are unneeded.


Solution

  • The text you quote (112.5.13 compendium v4.2) doesn't directly relate to unbinding it refers to deactivation, which in turn necessitates unbinding. Later in the spec (112.5.15) it states "For each reference using the event strategy, the unbind method must be called for each bound service of that reference."

    EDIT Ignore above, see comments below. In the current version of Felix SCR "generateAccessors" is enabled by default and you definitely don't need to write bind/unbind methods. IIRC in July 2011 that wasn't the case.