Spring.NET : Flirting with the dark side - No Fluff Just Stuff

Spring.NET : Flirting with the dark side

Posted by: Craig Walls on May 16, 2005

As mentioned in an earlier entry, I've been monkeying around with Mono on my MacOS X machine with the intent of experimenting with Spring.NET, the .NET port of Spring. After struggling a bit with Spring.NET's configuration XML, I finally managed to get a rough approximation of the Knight example from chapter 1 of Spring in Action to work under Spring.NET. Here's what I've learned thus far:

  1. Anywhere I'd use "bean" in the Java edition of Spring, I now use "object" in Spring.NET. This applies to both the XML file...

    <objects xmlns="http://www.springframework.net">
      <object name="lancelot" type="Habuma.Knight, Knight">
        <property name="quest">
          <ref object="dragonQuest"/>
        </property>
      </object>

      <object name="dragonQuest" type="Habuma.SlayDragonQuest, Knight"/>
    </objects>

    ...and when using the application context...

    IKnight knight = (IKnight) ctx.GetObject("lancelot");

  2. When specifying the object type, I must also specify which .NET assembly that the object class can be found in. For example, I'm compiling everything to Knight.exe, so my assembly name is "Knight". Thus to load an object of type "Habuma.Knight" from the "Knight" assembly, I set the type to "Habuma.Knight, Knight".

  3. Correctly specify the XML namespace. This is what frustrated me for several days before I finally figured it out. Be sure to set xmlns to "http://www.springframework.net" or else you'll get NullReferenceExceptions when the application context is loading (apparently this is only a problem when running under Mono...I don't have the same problem running under .NET on Windows).

For your amusement, here's the code I've been playing with. I'm using NAnt to build it, so you'll need NAnt installed. If you'd rather build it through VisualStudio.NET, then I leave that as an exercise for the reader.

Craig Walls

About Craig Walls

Craig Walls is a Principal Engineer, Java Champion, Alexa Champion, and the author of Spring AI in Action, Spring in Action, and Build Talking Apps. He's a zealous promoter of the Spring Framework, speaking frequently at local user groups and conferences and writing about Spring. When he's not slinging code, Craig is planning his next trip to Disney World or Disneyland and spending as much time as he can with his wife, two daughters, 1 bird and 2 dogs.

Why Attend the NFJS Tour?

  • » Cutting-Edge Technologies
  • » Agile Practices
  • » Peer Exchange

Current Topics:

  • Languages on the JVM: Scala, Groovy, Clojure
  • Enterprise Java
  • Core Java, Java 8
  • Agility
  • Testing: Geb, Spock, Easyb
  • REST
  • NoSQL: MongoDB, Cassandra
  • Hadoop
  • Spring 4
  • Cloud
  • Automation Tools: Gradle, Git, Jenkins, Sonar
  • HTML5, CSS3, AngularJS, jQuery, Usability
  • Mobile Apps - iPhone and Android
  • More...
Learn More »