SpringDotNet中没有上下文注册错误

时间:2011-12-16 11:46:18

标签: .net spring.net

我正在使用Spring.Net进行远程处理。 我将App.config文件的名称更改为NewApp.config文件。 CopyAlways属性设置为true。 IApplicationContext ctx = ContextRegistry.GetContext()给出了错误 没有上下文注册。使用RegisterContext方法或配置文件中的spring / context部分。

<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>

2 个答案:

答案 0 :(得分: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>

在some-other-file.xml中(将其设置为“始终复制”)

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

答案 1 :(得分:0)

删除对象部分并使用类似:

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