javaosgideclarative-services

Component instantiation and registration when extending abstract classes


It is my understanding that a component that extends an abstract class is properly instantiated by SCR but it isn't saved into the service registry. It is saved only if it implements an interface.

Is this correct?


Solution

  • The default is to use the directly implemented interfaces of the component implementation class for the service types. If the component implementation class extends a class, the interfaces implemented by the super class are not considered as part of the component implementation's default service types.

    To look up the type hierarchy for all interfaces would not be useful in that common interfaces, like Serializable, would be included in the default service types.

    So either have your component implementation class redeclare the desired interfaces of the super class, or use the service property of the Component annotation to explicitly declare the service types for the component.