2011-12-16 27 views
3

我正在使用Spring.Net進行遠程處理。 我將App.config文件的名稱更改爲NewApp.config文件。 CopyAlways屬性設置爲true。 IApplicationContext ctx = ContextRegistry.GetContext()給出的錯誤爲 沒有上下文註冊。使用RegisterContext方法或配置文件中的spring/context部分。SpringDotNet中沒有上下文註冊錯誤

<configSections> 
    <sectionGroup name="spring"> 
    <section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core" /> 
    <section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core" /> 
    </sectionGroup> 
</configSections> 
<spring> 
    <context> 
    <resource uri="config://spring/objects" /> 
    </context> 
    <objects xmlns="http://www.springframework.net"> 
    <object></object> 
    </objects> 
</spring> 
+0

代碼爲如下 - – user660232 2011-12-16 11:48:09

回答

4

您的問題是,現在你的配置不被解釋爲這樣的.NET,因爲你改變了它的名字。如果你想在一個外部文件中聲明瞭對象,你應該做的像這樣的App.config

<configSections> 
    <sectionGroup name="spring"> 
     <section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core" /> 
     <section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core" /> 
    </sectionGroup> 
</configSections> 
<spring> 
    <context> 
     <resource uri="config://spring/objects" /> 
     <resource uri="file://~/some-other-file.xml" /> 
    </context> 
    <objects xmlns="http://www.springframework.net"> 
    </objects> 
</spring> 

一些,其他-file.xml(它設置爲一直拷貝)

<?xml version="1.0" encoding="utf-8" ?> 
<objects xmlns="http://www.springframework.net"> 
    ....... 
</objects> 
0

刪除對象部分,使用這樣的:

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