如何在 OSGi 中使用多值(数组)属性?

How to use multi value(array) property in OSGi?

我有以下服务:

@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 作为数组值,以便有可能使用一组值,如图像所示:

如何实现?

使用 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));