0

“Greenpages 应用程序”是 Eclipse Virgo 站点中提供的示例 Web 应用程序,它提供了一起使用 OSGI 和 Spring DM 的示例,并且可以部署在 Virgo 容器中。请参阅:http: //www.eclipse.org/virgo/samples/。我能够毫无错误地运行该应用程序。但是一旦我尝试实现org.springframework.osgi.context.event.OsgiBundleApplicationContextListener接口,一切都出错了,我开始收到这个错误:

java.lang.IllegalArgumentException:尚未设置必需的属性“bundleContext”

OsgiBundleApplicationContextListener 接口提供了一种监听 BundleContext 事件的方法。请参阅:http ://docs.spring.io/osgi/docs/current/api/org/springframework/osgi/context/event/OsgiBundleApplicationContextListener.html

我的代码:

公共类 ApplicationContextObserver 实现 OsgiBundleApplicationContextListener { 私有瞬态 int countRefreshed = 0; 私人瞬态int countClosed = 0;

public void onOsgiApplicationEvent(OsgiBundleApplicationContextEvent evt) {
    if(evt instanceof
            OsgiBundleContextRefreshedEvent) {
        countRefreshed++;
    } else if(evt instanceof
            OsgiBundleContextClosedEvent) {
        countClosed++;
    }
}
public int getCountRefreshed() {
    return countRefreshed;
}
public int getCountClosed() {
    return countClosed;
}

}

和声明的bean:

<bean id="ApplicationContextObserver" class="greenpages.ApplicationContextObserver" />
<osgi:service ref="ApplicationContextObserver" interface="org.springframework.osgi.context.event.OsgiBundleApplicationContextListener" />      

更糟糕的是,有时这个错误根本不会出现,但是当我在容器中部署另一个包时,不会调用监听器。

出了什么问题(如果可能,您可以附加一个使用 Virgo Container、SpringDM 和此侦听器的运行示例)?

4

1 回答 1

0

请查看Migrating from Spring Dynamic Modules to Eclipse Gemini Blueprint。更多细节可以在Eclipse Gemini Blueprint Reference Guide中找到(尤其是第8.3 节。扩展器配置选项)。

于 2015-10-02T15:14:57.547 回答