In most cases, I have many components that have the same classes that must be introduced by the OSGi declaring service. Services will be used to execute some logic that will be the same for all derived components. Therefore, to avoid duplication of code, it would be better to use abstract classes. Is it possible to move DI reference methods (set / unset) to an abstract class. I am using Bnd.
Example:
@Component public class B implements IA { private ServiceC sc; @Reference public void setServiceC(ServiceC sc) { this.sc = sc; } public void execute() { String result = executeSomethingDependendOnServiceC();
I want to move the setter for ServiceC and the executeSomethingDependendOnServiceC() method to an abstract class. But what does it look like in OSGi in connection with the Bnd annotation. Just comment on the class with @Component does not work, because A and D will create different instances of the abstract class, and @Component is alsp creating the instance.
Maybe someone is experiencing the same problem and giving me some tips on what a workaround might look like. At least the best solution would be also good :)
christian.vogel
source share