2011-06-03 38 views
1

我將OSGi Equinox,GWT作爲bundle和Spring動態模塊進行集成。首先,我檢查沒有服務的GWT包,它運行。現在我想用Spring Dynamic Modules調用一個外部服務。這是我的XML文件來聲明和消費服務:與Spring動態模塊的NullPointerException

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

和:

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

在GreetingServiceImpl我的財產ZB和setter /吸氣:

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(); 
} 

如果在Equinox類型的「服務」中,我可以查看所有服務和消費者。它顯示以下內容:

{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] 

然後,顯示服務,並且我的應用程序ZBGWTApp是用戶。一切似乎都對。但是,如果我調試應用程序,當我在zb.checkUser()行上中斷線程時,zb的值爲NULL。也就是說,服務引用沒有被注入,爲什麼?

回答

0

嗯,我解決了這個問題。只有我把屬性設置爲靜態並且它運行了!

1

我有同樣的錯誤,我已經刪除了構造函數調用解決它,它應該由Spring自動

public void start(BundleContext bundleContext) throws Exception { 
    Activator.context = bundleContext; 
    // NOTE vobmaniuk: do not call HelloService(), it must be created by spring. 
    // context.registerService(IHelloService.class.getName(), new 
    // HelloService(), null); 
} 
完成