2015-11-19 59 views
1

我正在接受有關組合Restlet/Spring的培訓,但有些事情我仍然不明白......我希望你能幫助我。實際上,我正在嘗試使用Spring Restlet的注入依賴系統(如本教程中所示:http://restlet.com/technical-resources/restlet-framework/guide/2.3/introduction/getting-started/maven-spring)。所以我試圖自己做,但沒有奏效。我的代碼返回此異常:Q - Restlet/Spring - NotWritablePropertyException與教程示例?

org.springframework.beans.factory.BeanCreationException:錯誤創建名稱爲豆「basecampComponent」在ServletContext的資源定義[/WEB-INF/applicationContext.xml的]: 無法解析參考bean'basecampAppliction',同時設置bean屬性'defaultTarget';嵌套的異常是org.springframework.beans.factory.BeanCreationException:在ServletContext資源[/WEB-INF/applicationContext.xml]中定義名稱爲'basecampAppliction'的bean時出錯: 設置屬性值時出錯;嵌套異常是org.springframework.beans.NotWritablePropertyException:豆類的無效的屬性「根」 [com.mycompany.restlet.basecamp.application.BaseCampApplication]: Bean屬性「根」不可寫或有一個無效的設置方法。 setter的參數類型是否與getter的返回類型相匹配?

所以我一直在尋找的文件「applicationContext.xml中」,這是他的內容:

<bean id="basecampComponent" class="org.restlet.ext.spring.SpringComponent"> 
    <property name="defaultTarget" ref="basecampAppliction" /> 
</bean> 
<bean id="basecampAppliction">class="com.mycompany.restlet.basecamp.application.BaseCampApplication"> 
    <property name="root" ref="router" /> 
</bean> 
<!-- Define the router --> 
<bean name="router" class="org.restlet.ext.spring.SpringBeanRouter" /> 

有人有一個想法,我在那裏可以尋找一種方法來調試呢?

順便說一下,我在Java 1.8.0_60。

感謝您的幫助。 Benjamin

+0

請把'com.mycompany.restlet.basecamp.application.BaseCampApplication'放在你的問題中,或者更確切的說是** root **變量的設置器 – Vihar

+0

'package com.mycompany.restlet.basecamp.application; import org.restlet.Application; import org.restlet.ext.spring。SpringBeanRouter; 公共類BaseCampApplication延伸申請{ \t }' 這是基本的代碼。一位朋友告訴我試着在裏面添加這個代碼: 'private SpringBeanRouter root; public void setRoot(SpringBeanRouter route){this.root = route; } public SpringBeanRouter getRoot(){ return this.root; } ' 我試過了,但沒有奏效。 – bconotte

+0

對不起,此演示文稿。我是一個關於在stackoverflow上發佈的新手。 – bconotte

回答

0

我認爲在Application類中沒有root屬性。你應該在你BaseCampApplication類添加一個,並用它來配置你的應用程序(見createInboundRoot法),如下所述:

public class BaseCampApplication extends Application { 
    private Restlet root; 

    public Restlet createInboundRoot() { 
     return root; 
    } 

    public void setRoot(Restlet root) { 
     this.root = root; 
    } 
} 

希望它可以幫助你, 蒂埃裏

+0

謝謝蒂埃裏。 實際上,類應用程序中似乎有一個名爲「inboundroot」的屬性。當你調用方法「createInboundRoot()」時,你綁定這個屬性。 順便說一句,我發現我的問題的解決方案在您的答案在這個網站上。 (http://stackoverflow.com/questions/28287377/spring-restlet-100-xml-configuration)。你是我的救世主! – bconotte

1

尋找一些信息在後網絡,我有一個假設我是如何解決這個問題的。

在此鏈接(Spring & Restlet : 100% XML configuration?),他結合與應用的屬性「inboundroot」路由器。所以我認爲有一個最小的變化(在教程中沒有注意到)。事實上,我嘗試了檔案中提出的項目(不起作用)和你自己編寫教程的方式。這又是兩個解決方案。

最終的溶液通過改變屬性爲「inboundroot」到「根」的名稱由如此。

「永不信任政黨成員」

感謝你把幫助我的時間。