简体   繁体   中英

Spring.net Context Hierarchies not working

Spring version : 2.0.0.40000 Runtime : .NET 4.5

Taking the example shown here www.springframework.net/.../objects.html and in the API http://springframework.net/docs/1.3..../webframe.html - ContextHandler

I have the following

Code:

<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 name="child">
    <section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core"/>
    </sectionGroup> 
  </sectionGroup> 
</configSections>

<spring>
  <objects xmlns="http://www.springframework.net">
    <import resource="assembly://ProjectDLL/Config/Spring.xml"/> 
  </objects>

  <child>
    <objects xmlns="http://www.springframework.net">
      <object name="eventLog"
          type="System.Diagnostics.EventLog, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
          >
        <constructor-arg type="string" name="logName" value="v1"  />
        <constructor-arg type="string" name="machineName" value="."  />
        <constructor-arg type="string" name="source" value="v1"  />
      </object>
    </objects>
  </child>  

  <context name="Parent">
    <resource uri="config://spring/objects"/>
    <context name="child">
    <resource uri="config://spring/child/objects"/>
    </context>
  </context>
</spring>

Calling

ContextRegistry.GetContext();

of any context names results in

Message --- Error creating context 'ChildContext': Errored while postprocessing an object factory.

I've tried all the various naming for including Child, ChildContext, Children, all resulting in the same error.

In my example, I use a resource file that contains my objects ( ), if I do not import my own XML file, it works but importing it means that the child does not work. If I define the child in the same xml file, I get "Error creating context 'Parent': There are multiple root elements"

I know this is most likely a configuration issue and would appreciate any help.

Having not fully understood the error I was getting or why, the workaround was to use "depends-on" for startup. The spring xsd defines quiet a few here http://www.springframework.net/xsd/spring-objects.xsd

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM