OSGi蓝图:如何从BundleListener接口调用onBundleChanged()方法?

劳伦·卡瓦巴(LaurentKavaba)

我试图在一个类中实现BundleListener接口以检索捆绑软件更改。我正在尝试使其工作,但似乎未调用我的onBundleChanged()方法。可能是因为未在“ Activator”类中实现它。我没有线索。

我想获得最新的捆绑软件更改,因为我想开发一个应用程序,其中捆绑软件可以在运行时作为插件安装。我认为通过使用BundleListener接口,我可以对可以安装在我的Apache Karaf环境中的Bundles进行授权。

摘自Blueprint.xml

<bean id="MyBundleListener" class="com.hallo.service.MyBundleListener"/>

我的课

public class MyBundleListener implements BundleListener {

@Override
public void bundleChanged(BundleEvent event) {
    System.out.println("bundleChanged() -> Just to test if it works");
}
}

在Apache Karaf中,我使用

log:tail

查看该方法是否被调用,但到目前为止没有结果。

克里斯汀·施耐德(Christian Schneider)

对于BundleListener而言,创建bean是不够的。您还必须将BundleListener添加到BundleContext。

您可以在bean的init方法中执行此操作。看到

bundleContext.addBundleListener

同样不要忘记在destroy方法中再次删除侦听器。

https://osgi.org/javadoc/r4v43/core/org/osgi/framework/BundleContext.html

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章