在 karaf 3.0.2 中使用声明性服务时如何获取当前包的 BundleContext 实例

How can I get current bundle's BundleContext instance while using declarative services in karaf 3.0.2

在 karaf 3.0.2 上的 ONOS 中,我希望获取当前 bundle 的 BundleContext 实例以跟踪 bundle 的状态并进行配置。但是ONOS使用声明式服务,所以我不能使用BundleContext.getServiceReference()这样的函数来获取它。 谁能帮帮我?

您可以在使用 DS 时在 @Activate 方法中注入 BundleContext。