通过 org.osgi.service.component 注释抽象组件

Abstract components via org.osgi.service.component annotations

我正在从 org.apache.felix.scr 注释迁移到 org.osgi.service.component 注释。我有一组继承自公共抽象 class 的组件。在 felix 的情况下,我可以在超级 class 上使用带有选项 componentAbstract=true@Component 注释,然后在超级 class 中使用 @Reference 注释。我找不到如何将其迁移到 osgi 注释。

是否可以在组件的超 class 中使用组件注释?如果是这样,那么处理属性和元类型生成的合适方法是什么?

所以,我正在寻找的是这样的东西

/* No component definition should be generated for the parent, as it is
   abstract and cannot be instantiated */
@Component(property="parent.property=parentValue")
public abstract class Parent {
  @Reference
  protected Service aService;

  protected activate(Map<String,Object> props) {
    System.out.println("I have my parent property: "+props.get("parent.property"));

  @Override
  public abstract void doSomething();
}

/* For this class, the proper Component definition should be generated, also
   including the information coming from the annotations in the parent */
@Component(property="child.property=childValue")
public class Child extends Parent {

  @Activate
  public activate(Map<String,Object> props) {
    super.activate(props);
    System.out.println("I have my child property: "+props.get("child.property"));
  }

  public void doSomething() {
    aService.doSomething();
  }
}

默认情况下,BND 不会处理父 类 中的 DS 注释。您可以使用 -dsannotations-options: inherit 更改它,但请参阅 http://enroute.osgi.org/faq/ds-inheritance.html 为什么您不应该这样做!


2021-02-23 更新:上面提到的页面似乎不再可用。我不知道它是被移到别处还是被简单地删除了,但它的内容(以 Markdown 格式)在 GitHub 上仍然可用:https://github.com/osgi/osgi.enroute.site/blob/pre-R7/_faq/ds-inheritance.md