7

org.apache.felix.scr注釈から注釈に移行していorg.osgi.service.componentます。共通の抽象クラスから継承する一連のコンポーネントがあります。フェリックスの場合、スーパー クラス@Componentのオプションでアノテーションを使用してから、スーパー クラスでアノテーションを使用できます。これを osgi アノテーションに移行する方法が見つかりません。componentAbstract=true@Reference

コンポーネントのスーパークラスでコンポーネントアノテーションを使用することは可能ですか? もしそうなら、プロパティとメタタイプの生成を処理する適切な方法は何ですか?

だから、私が探しているのは、このようなものです

/* 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 アノテーションを処理しません。これは で変更できますが、 http://enroute.osgi.org/faq/ds-inheritance.html変更しない理由-dsannotations-options: inheritを参照してください。


2021-02-23 UPDATE: 上記のページは利用できなくなったようです。他の場所に移動されたのか、単に削除されたのかはわかりませんが、そのコンテンツ (Markdown 形式) は GitHub で引き続き利用できます: https://github.com/osgi/osgi.enroute.site/blob/pre-R7/_faq /ds-inheritance.md

于 2016-12-22T10:27:41.993 に答える