OSGi 控制台 "ls -c":尽管没有提供程序,但引用已绑定

OSGi console "ls -c": References are bound although there is no provider

在调试服务绑定问题时,我调用了命令 ls -c(或等效的 list -c)并为我的组件获得了以下输出:

21      Component[
        name = org.example.myproject.repo
        activate = activate
        deactivate = deactivate
        modified =
        configuration-policy = optional
        factory = null
        autoenable = true
        immediate = true
        implementation = org.example.myproject.RepositoryServiceHandler
        state = Unsatisfied
        properties =
        serviceFactory = false
        serviceInterface = null
        references = {
                Reference[name = Repository, interface = org.example.core.repository.api.Repository, policy = static, cardinality = 1..1, target = null, bind = bindRepository, unbind = unbindRepository]
                Reference[name = IRepositoryClient, interface = org.example.core.repository.client.RepositoryClient, policy = static, cardinality = 1..1, target = null, bind = bindRepositoryClient, unbind = unbindRepositoryClient]
        }
        located in bundle = org.example.myproject_0.20.1348.3 [30]
]
Dynamic information :
  The component is satisfied
  All component references are satisfied
  Component configurations :
    Configuration properties:
      component.name = org.example.myproject.repo
      component.id = 34
    Instances:
      org.eclipse.equinox.internal.ds.impl.ComponentInstanceImpl@75b98b5a
        Bound References:
        String[org.example.core.repository.client.RepositoryClient]
                -> org.example.core.repository.client.impl.RepositoryClientImpl@67680c91
        String[org.example.core.repository.api.Repository]
                -> org.example.core.repository.api.impl.RepositoryImpl@1c27ecd6

我想找到提供接口 org.example.core.repository.client.RepositoryClient 的包,因此搜索了 ls -c 的完整输出。令我惊讶的是,没有其他事件发生(即我的组件中只有两个引用)。

怎么可能没有provider,还绑定了service呢?不应该有 serviceInterface = org.example.core.repository.client.RepositoryClient 的提供程序组件吗?

一段时间后我自己想出了解决方案,但我想我可能还是会在这里分享它,以防其他人遇到同样的问题。

我没有找到服务提供商的原因是 ls -c 只列出了通过声明式服务注册的服务。相反,该服务是以编程方式注册的,因此未被 ls -c.

列出

要搜索所有服务提供商,需要使用service命令:

osgi> services (objectClass=org.example.core.repository.client.RepositoryClient)

{org.example.core.repository.client.RepositoryClient}={service.id=83}
  Registered by bundle: org.example.core.repository.client_1.2.102 [45]
  Bundles using service:
    org.example.myproject_0.20.1348.3 [30]