【问题标题】:How to use multi value(array) property in OSGi?如何在 OSGi 中使用多值(数组)属性?
【发布时间】:2016-02-09 16:56:48
【问题描述】:

我有以下服务:

@Component(
        immediate = true,
        metatype = true)
@Service
@Property(name = EventConstants.EVENT_TOPIC, value = {ReplicationAction.EVENT_TOPIC})
public class MyService implements EventHandler {

    @Property
    private static final String MULTI_PROPERTY = "config.multiproperty";

    ........
    //another implementation
    ........
}

我希望MULTI_PROPERTY 成为数组值,以便有可能使用图像上的一组值:

如何实现?

【问题讨论】:

    标签: osgi aem apache-felix


    【解决方案1】:

    使用unbounded属性指定多值属性,使用cardinality属性限制条目数。

     @Property(unbounded = PropertyUnbounded.ARRAY, cardinality=10, label = "Some Label")
     private static final String MULTI_PROPERTY = "config.multiproperty";
    

    为了读取属性数组,您可以使用PropertiesUtil#toStringArray() 方法

    PropertiesUtil.toStringArray(properties.get(MULTI_PROPERTY));
    

    【讨论】:

      猜你喜欢
      • 2016-01-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-26
      • 2017-06-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多