2010-03-02 51 views
0

我有一些似乎無法解決的Spring和NHibernate問題。我正在使用NorthWind項目作爲示例。現在,我得到這個錯誤:Spring.Net + NHibernate - 'http://www.springframework.net/database:provider'元素沒有聲明

'MyNamespace.MyClass.MyFunction: 
Spring.Objects.Factory.ObjectDefinitionStoreException : Line 6 in XML document from assembly [MyAssembly, Version=0.0.1.0, Culture=neutral, PublicKeyToken=334479e19ddfb52d], resource [MyNamespace.Dao.xml] violates the schema. The 'http://www.springframework.net/database:provider' element is not declared. 
    ----> System.Xml.Schema.XmlSchemaValidationException : The 'http://www.springframework.net/database:provider' element is not declared.' 

的是指我的XML以下位:

<db:provider id="DbProvider" 
      provider="System.Data.SqlClient" 
      connectionString="Data Source=MyServer\MyDatabase;Initial Catalog=master;Integrated Security=True"/> 

我已經包含了正確的命名空間,增加了XSD的到我的項目,並添加解析器我App.config文件:

<section name="parsers" type="Spring.Context.Support.NamespaceParsersSectionHandler, Spring.Core" /> 

<spring> 
    <parsers> 
    <parser type="Spring.Data.Config.DatabaseNamespaceParser, Spring.Data"/> 
    </parsers> 
</spring> 

但它似乎沒有拿起它。任何想法,爲什麼我得到這個錯誤?我讀到的每個地方都說這個錯誤是因爲我沒有定義解析器,但我顯然是這樣。

回答

1

它根本沒有加載我的App.config文件,所以它永遠不會加載解析器。

我添加以下代碼:

NamespaceParserRegistry.RegisterParser(typeof(DatabaseNamespaceParser)); 

和它的工作。