至少需要一个实现?

Require at least one implementation?

如何在 osgi 中要求至少实现某个 api 接口?

例如,我有一个使用另一个组件(在本例中为 Map)的 @Component YellowBlock:

@Component
public class YellowBlock implements BlockProvider {
@Reference
public void setMap(Map map){

当没有其他组件实现 Map 接口时,此组件永远不会 "goes live"(无法被 ServiceTracker 看到)在我的 osgi 容器中。例如这个:

@Component
public class MapImpl implements Map{

如果我手动将这个添加到容器中 YellowBlock 组件 "goes live"。

[edit] 我的基数似乎是正确的:cardinality="1..1"。我还发现了一些关于 @reference 注释超时的讨论,但在那上面找不到太多内容。

问题自己回答。

您问了 "how can I require at least one implementation of a certain API interface",然后您的示例代码就是这样做的。