A menagerie of Spring configuration options - No Fluff Just Stuff

A menagerie of Spring configuration options

Posted by: Craig Walls on December 5, 2006

Some of my faithful readers already know (and the rest of you are about to find out) that my wife and I are only weeks away from the birth of our second child. It's an exciting time and it's meant a lot of preparation for the baby's arrival. Part of that preparation has been to assemble furniture and other baby-related gizmos. Consequently, my toolbox has been open more than it has been closed.

On one occasion, as I was digging around for a particular screwdriver, I realized that I have (literally) hundreds of screwdriver bits, all in different shapes and sizes. Of course, I have the standard flat-head and Phillips-head screwdriver bits. But I also have some star-shaped, square-head, hexagon-head, and other bits that I'm not even sure how to describe. Many of the bits have only been used once or twice and some have never seen any action at all. I could throw them out, but they're not taking up much space and who knows if my next project may call for that star-shaped screwdriver bit.

What does this have to do with Spring? Good question...let me continue...

In the past week or so, there have been several announcements and discussions regarding the various ways that Spring can be configured. In all of the excitement, I've had several different configuration options brought to my attention and I thought I'd present links to them all here for your amusement.

  • Jacn - Pure-Java (ie, no annotations) approach to configuring Spring
  • Spring JavaConfig - Annotation-based configuration for Spring...with a twist.
  • Pitchfork - EJB 3-style dependency injection and AOP using annotations.
  • Spring Annotations - A basic approach to Spring configuration using annotations.
  • Craig's Spring annotations - My own blog entry on how to extend Spring to support annotations.
  • SpringBean Builder - Groovy builder for Spring configuration. (Part of Grails project.)
  • Springy - A JRuby-based DSL for building Spring configuration files.
  • XBean - Provides the ability to create a custom XML language for configuring Spring.
  • Naturally, you can also use good old-fashioned XML configuration, just as you've always been able to do in Spring. Except that it has gotten much better in Spring 2.0 with XML namespace support and the ability to create custom configuration elements.

    Which of these approaches is the best? I don't know. I suppose that it all depends on the task.

    For me, Spring XML is that old familiar #2 Phillips-head screwdriver that I use on most occasions. It's not perfect, but it fits most situations and has held up pretty well. Yeah, I may have stripped out a few screw heads with it, but was probably because I wasn't using it right.

    Meanwhile, the Groovy building and Springy are those hex-shaped and star-shaped bits that may come in handy from time to time. Spring JavaConfig is the shiny new tool in my toolbox and I'm not sure how I'll use it yet--but I'm sure it'll come in handy for something. And Pitchfork is that odd-shaped screwdriver bit that's hard to describe and that I'm not ready to throw out yet...just in case I need it.

    I'm not encouraging or discouraging the use of any of the Spring configuration options any more than I'd insist that you use a Phillips-head screwdriver for all of your screwdriving needs. I still think that Spring XML is perfectly fine for most everything. Nevertheless, I'm glad that I have several tools in my toolbox for those situations where Spring XML won't cut it.

    When I find the time (probably not soon--did I mention that there's a baby on the way?), I'll try to write up some how-to and comparison articles highlighting how to configure Spring with each of the configuration options listed above.

    I'm still eagerly awaiting a YAML option for configuring Spring. If anyone knows of such an animal, let me know. For that matter, if there's some other configuration option that I've missed, let me know and I'll add it to the list.

    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 »