2014-02-07 29 views
1

後空我有這些豆子:注入豆重新啓動Tomcat的使用Spring和Axis2

<bean id="Child" class="test.Child"></bean> 

<bean id="Parent" class="test.Parent"> 
    <property name="child" ref="Child" /> 
</bean> 

我用Axis2中,春季與Hibernate Tomcat上。 Axis服務位於Parent bean中。它在services.xml中映射爲SpringBeanName,包括正確的ServiceClass。我放在獲取日誌,並設置方法父bean中的兒童豆變量:

private Child child; 
public void setChild(Child child) { 
    this.child = child; 
    System.out.println(child); 
} 
public Child getChild() { 
    System.out.println(child); 
    return child; 
} 

我有一個名爲在啓動一個Spring初始化服務,在服務實施ServiceLifeCycle加載彈簧的啓動方法。

ClassLoader classLoader = service.getClassLoader(); 
    ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(
      new String[] { "classpath:spring/applicationContext.xml" }, false); 
    applicationContext.setClassLoader(classLoader); 
    applicationContext.refresh(); 

這是一個簡單的示例項目,因爲邏輯實際上相當複雜。無論如何,結果是:

  • 在Axis2 war distribution的服務中部署AAR,一切都加載完美,set方法實際上是用非null對象調用的。
  • 每次調用服務時,都會成功讀取子項。

問題是何時Tomcat重新啓動。在起始日誌中,使用非空對象調用set方法。但是當服務被調用時 - 空指針異常,子節點爲空。重新部署AAR可以使所有工作重新開始。但是在重新啓動後 - 孩子再次爲空。

發生了什麼事?每一個幫助將不勝感激。

  • 注意:我不創建與新的孩子。所有的bean都是默認的。我試圖用原型範圍沒有成功。會議並要求範圍拋出一個異常,這些範圍並不認可:

    沒有實施的範圍註冊的「...」

  • 注2:在取消在context.xml中的標籤在conf文件夾沒有改變了一切。更改後我重新啓動了Tomcat。

+0

奇怪......我也在好奇地等待解決方案。 – RMachnik

回答

0

我發現了一個解決方案,但它並沒有涵蓋所有情況。將services.xml中的服務範圍從application更改爲request(或其他兩個)可以修復問題,這似乎有點合乎邏輯。

備註:如果application範圍是您真正需要的範圍,則此修補程序不適用。