springosgieclipse-virgospring-dm

Spring DM (Dynamics Modules), OSGI and Greenpages application


The 'Greenpages app' is a sample web application available in Eclipse Virgo site that provides a example of using OSGI and Spring DM together and can be deployed in Virgo container. See: http://www.eclipse.org/virgo/samples/ . I was able to run the app with no errors. But as soon as I try to implement the org.springframework.osgi.context.event.OsgiBundleApplicationContextListener interface, everything goes wrong, and I start getting this error:

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

OsgiBundleApplicationContextListener interface provides a way to listening BundleContext events. See: http://docs.spring.io/osgi/docs/current/api/org/springframework/osgi/context/event/OsgiBundleApplicationContextListener.html

My code:

public class ApplicationContextObserver implements OsgiBundleApplicationContextListener { private transient int countRefreshed = 0; private transient 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;
}

}

And the declared beans:

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

To get things worst, sometimes this error does not appear at all, but the listener do not get called when I deploy another bundle in the container.

What is going wrong (if possible, can you attach a running example using Virgo Container, SpringDM and this listener)?


Solution

  • Please have a look at 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).