2008-11-19 56 views
0

所有我可以在網上搜索使用指定由XmlApplicationContext(sFileName)將讀取的xml上下文定義文件的格式是什麼?

contextToGetSprungObjects = ContextRegistry.GetContext(contextname) 

我想用

contextToGetSprungObjects = new XmlApplicationContext(sXmlFileName) 

(我打電話到DLL中檢索到的上下文定義的App.Config中模式(例需要Spring.net)從另一個可執行文件(MsWord),所以app.config的方法是)。我試圖偷偷在MyDll.dll.config ..沒有飛。 關於使用XmlApplicationContext方法從指定的XML文件中讀取它,我收到以下錯誤

{"Error registering object with name '' defined in 'file [D:\\Work\\Seven\\WordAutomation\\ContentControls\\WordDocument1\\bin\\debug\\MyWPFPlotPopup.dll.config]' : There is no parser registered for namespace ''\r\n<configSections><sectionGroup name=\"spring\"><section name=\"context\" type=\"Spring.Context.Support.ContextHandler, Spring.Core\" /></sectionGroup><section name=\"log4net\" type=\"log4net.Config.Log4NetConfigurationSectionHandler, log4net\" /></configSections>"} 

這使我相信,這兩種方法需要他們的XML不同形狀的瓶子。我搜索了高和低,但所需的XML的架構迴避我..我能找到的一切使用X.exe.config或Web.config。有人能指出我對Spring.net有效的xml上下文定義嗎?

<spring> 
    <context> 
     <context name="MyApplication"> 
      <resource uri="file://Resources/MyApplicationContext.xml"/> 
     </context> 
    </context> 
</spring> 

我覺得這是我想對Spring.net重新進行添加

回答

2

Spring.NET文檔是在痛苦中一個很好的鍛鍊

你檢查出的參考文檔的introductorily節 「Basics - containers and objects」? Imho章節5.2.1「配置元數據」和5.2.2「實例化容器」非常清楚地表明瞭你試圖實現的目標。你的痛點是什麼?我們很樂意收到您的改進建議!

我還想建議您將Spring for .NET相關問題發佈到我們的community forums--它更有可能在那裏回答您的問題。

歡呼聲, 埃裏希

+1

我本來期望的XmlApplicationContext文檔(或任何一般這樣的解析器類)有某種聯繫或指針,以文件的形式,預計。一個例子也可以滿足由於缺乏對這篇文章的回覆。我會說一羣人會從中受益 – Gishu 2009-01-05 06:13:19

2

最後清除這一障礙在app.config的相關部分。 XmlApplicationContext不讀取app.config中的中間映射xml ...它直接讀取指向爲資源元素的內容。它不會讀取app.config格式 - 它在Spring.net中由ContextRegistry類使用。 Spring.net文檔是一個很好的練習。

context = new XmlApplicationContext("file://Resources/MyApplicationContext.xml"); 

其中此xml具有以下形式。

<?xml version="1.0" encoding="utf-8" ?> 
<objects xmlns="http://www.springframework.net"> 
    <object id="Wilma" type="WhatIsSpring.Wilma, WhatIsSpring"/> 
    <object id="Fred" type="WhatIsSpring.Fred, WhatIsSpring"> 
    <property name="TheDependency" ref="Wilma"/> 
    </object> 
</objects>