Search code examples
springgwtosgiequinox

NullPointerException with Spring Dynamic Modules


I am integrating OSGi Equinox, GWT as bundle and Spring Dynamic Modules. Firstly I check GWT bundle without services and it runs. Now I wish to call a external service with Spring Dynamic Modules. These are my XML files to declare and consume the service:

<bean name="ServicioZB" id="zbservice" class="service.ZBService"/>
<osgi:service ref="zbservice" interface="service.IZBService"/>

And:

<osgi:reference id="service">
    <osgi:interfaces>
        <value>service.IZBService</value>
    </osgi:interfaces>
</osgi:reference>

In GreetingServiceImpl I have the property zb and setter/getter:

private IZBService zb;
public IZBService getZb() {
    return zb;
}

public void setZb(IZBService zb) {
    this.zb = zb;
}
public boolean greetServer(String input, String input2) throws Exception {
    return this.zb.checkUser();
}

If in Equinox type "services" I can view all services and consumers. It shows the following:

{service.IZBService}={org.springframework.osgi.bean.name=zbservice, Bundle-SymbolicName=zbservice, Bundle-Version=3.0.0, service.id=56}
 Registered by bundle: zbservice_3.0.0 [56]
 Bundles using service:
 ZBGWTApp_1.0.0 [57]

Then, the service is shown, and my application ZBGWTApp is the consumer. All seems right. However, if I debug the application, when I break the thread on line zb.checkUser(), the value of zb is NULL. It is to say, the service reference is not injected, why?


Solution

  • Well, I solve the problem. Only I put the attribute as static and it runs!!!