Spring DM(动态模块)、OSGI 和 Greenpages 应用程序

Spring DM (Dynamics Modules), OSGI and Greenpages application

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

java.lang.IllegalArgumentException: required property 'bundleContext' has not been set

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

我的代码:

public class 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 和此侦听器的 运行ning 示例)?

请看Migrating from Spring Dynamic Modules to Eclipse Gemini Blueprint. More details can be found in Eclipse Gemini Blueprint Reference Guide (especially section 8.3. Extender Configuration Options).