Monday, October 10, 2005

Spring Books Roundup

Spring is hip these days, so I decided to learn a bit more about it. I had used Avalon a while ago, I was attracted by its design by component and the way it seemed to lay out a proper infrastructure to build a server application. In the end, I was a bit disappointed, it required a bit too much glue code for my taste and did not provide that much in exchange. I don't remember if, at that time, it was advertised as IoC (Inversion Of Control) container. This experience is one of the reasons why I did not jump on the Spring ship.
I have read 3 books, here is what I thought of them, briefly:
  • Spring: A Developer's Notebook, by O'Reilly: I enjoyed reading that book, because it is well written and has a good structure. It explains what is dependency injection by doing it without Spring, with Spring. But for a more complete understanding, I would recommend Fowler article. There is an interesting chapter on Swing with Spring. Minor drawbacks is that it does not talk about Spring Timers and has very little on Remoting. But I would recommend that book.
  • Spring In Action, by Manning: I was disappointed by that one, because there is not much more information than in O'Reilly, it is a bit less practical to use. While it is a bit more detailed than O'Reilly, I did not find the extra information very useful in general. Remoting is better covered here than in O'Reilly, but there is nothing on Swing.
  • Professional Java Development With The Sring Frampework, by Wrox: I liked that one better than Manning, but again information inside is very similar. I find the explanations more complete. Inversion Of Control is well presented (it is even comparing constructor injection with method injection). It gives examples of alternatives to XML configuration. Remoting is covered in greater details than Manning. I would recommend it over Manning anytime, and if it included a Swing chapter, I would recommend it over O'Reilly as well.
You can wonder a bit why there are 3 books on Spring, that similar. I believe there is space for other intelligent presentations of Spring. Subjects are often treated superficially. For example, look at the Fowler article versus the best chapter about IoC, the one from Wrox, and you'll see how much more detailed it could have been. I find it a bit shocking since IoC is the basis of Spring. It would have been good to see a book explaining why Spring chose that particular design over another, for the main features, and presenting alternatives better. I would also have welcomed a book explaining the use of maybe just a few Spring aspects, but in the frame of a big, commercial application. For example after reading those books, it is not immediately clear to me what are Spring benefits when using Swing support versus other solutions. Another critic is that all those books were written around the same time, and are sometimes already obsolete. None of them describes Spring JDK 1.5 support (for transactions or JMX or metadata). The official free Spring reference book seems better in many ways.

Those books showed me Spring could be useful in some projects:
  • if you want remoting.
  • if you want to promote clean code, then you can promote the "Spring way". It is a good one.
  • if you want to use JSF. Spring makes JSF easy and natural to use.
On top of it you get AOP for easy debugging or profiling, which is always useful at some point.

I am not convinced about Spring when it comes to:
  • JDBC or database use: while Spring has a well done framework, Hibernate or iBatis have a very good API that makes Spring abstraction useless.
  • MVC: it is does seem that much better than alternatives, nor much less intrusive (OK you can test it easily). Anyway I am not that big a fan of web MVC after having seen real world .NET projects without strict MVC well maintainable. I find the JSF backing beans at least as good and more flexible. Continuation frameworks are interesting too, but I am worried of their performance impact and scalability.
  • Transactions: I just don't think manual transactions are that bad or ugly or less maintainable. But using Spring for them is not necessarily a bad idea either.
To me, the main alternative to Spring, and a very good one, is JBoss. I will elaborate on that subject later in another post.

Categories: , , ,


  1. Those books showed me Swing could be useful in some projects:
    You surely mean Spring not Swing. :)

  2. >Spring does not seem to make use of >any JDK 1.5 new features.

    See the @Transactional annotation for demaracting transactions in source metadata. See the @ManagedResource annotation for describing JMX management metadata.

    Spring supports 1.5 nicely, it just does it in away where it still runs on 1.3 because that is important to its customer base.

  3. >JDBC or database use: while Spring >has a well done framework, Hibernate >or iBatis have a very good API that >makes Spring abstraction useless.

    ORM is not appropriate for all types of database access. iBatis does not allow execution of adhoc SQL.

    Spring JDBC exists to make it easy to execute adhoc, one-liner SQL calls against a datasource in the context of a transaction.

    That's a very valid need.

  4. I updated the post about JDK 1.5 support. I will add a comparison with the good Spring Reference Book later.

    About Spring JDBC, both Hibernate and iBatis allows you to write 1 line SQL calls against a datasource. You do need other lines for transaction demarcation, which I consider a good thing. And even that I suppose could be taken care of using the right annotations.

  5. Sorry but I have to disagree with your comments that Spring is useless for database use, especially in the case of JDBC. For JDBC the only thing you really need to be concerned about is your SQL...Spring handles most of the other stuff for you which is good. Why should I write that stuff if its already being done by a well-tested framework?

    Its very useful to use the Spring templates for Hibenate, IBATIS, etc. for the very same reasons. How can you argue about common exception handling regardless of the ORM tool you happen to be using? Or ease of transaction handling? I don't know why you'd want to write transaction handling code on your own if there is a well-written, well-tested, framework out there that already does it. Spend time on the stuff that matters...not the glue.