3
我正在从org.apache.felix.scr
注释迁移到org.osgi.service.component
注释。我有一组从一个共同的抽象类继承的组件。在felix的情况下,我可以在超类中使用@Component
注释和componentAbstract=true
选项,然后在超类中使用@Reference
注释。我找不到如何将其迁移到osgi注释。通过org.osgi.service.component注释的抽象组件
是否有可能在Component的超类中使用Component注释?如果是这样,那么处理属性和元类型生成的适当方式是什么?
所以,我找的,是这样的
/* 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();
}
}
感谢您的链接。解释清楚,但真正关注不同捆绑中的父母。在我的情况下,两个类都是同一个包的一部分,所以这些参数并不真正成立。 –
但是,我会将抽象类重写为一个工厂组件,并制作适配器,以完成子类中的所有专用实现。 –
使用Maven捆绑插件可以使用以下配置: '<配置> <指令> <_dsannotations选项>继承 _ dsannotations选项> 指令> 配置>' – Puce