0

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)?

JohnMake0
  • 25
  • 4
  • Spring DM is dead for a long time already, you should be using the Eclipse Virgo classes not the old Spring DM ones. – M. Deinum Oct 01 '15 at 12:47
  • OK. I can remove SpringDM from classpath but I need to keep Spring core itself since my project is Spring-based. How classes from Eclipse Virgo I need to use (and how I need to do that the right way) to make everything work using BundleContext listener? Can you provide any maven project example ? Thanks!! – JohnMake0 Oct 01 '15 at 14:33

1 Answers1

0

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).

Florian Waibel
  • 221
  • 2
  • 9