7

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

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

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

/* 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();
  }
}
4

1 回答 1

11

默认情况下,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-继承.md

于 2016-12-22T10:27:41.993 回答