Monday, October 22, 2007

I relented to Spring MVC; easy install IE7 feed reader web application

I have been actively using the Spring Framework for almost 2 years exactly. I really love it and use in all my DAOs. That said, until recently I have resisted the temptation to use Spring MVC. I didn't actually like Spring MVC (I have tried to use it several times but found it hard to convert). I was used to the structure that comes with Struts 1.2.X, I was more than happy to use the Spring ActionSupport which gives my Struts actions access to the Spring WebApplicationContext. What I liked about Struts 1.2.X is that you can give your struts-config to another Struts developer and they can work out exactly what is happening without much effort, this is a strength. I thought Spring MVC was a little too much of a free for all. Spring Web Flow gives Spring more structure but I was familiar with Struts and was understandably resistant to change. I found the idea of a ModelAndView class, multiple controllers, and view resolvers a little strange (as Struts usually has one controller).

I have finally relented and started to write with Spring MVC. This came about as I was recently working with XFire to produce web services and gradually discovered that XFire's elegance owed much to the internal use of Spring MVC. I don't know what has changed but I am suddenly much more comfortable with Spring MVC (maybe because it is easier in Spring 2.0, maybe it is just my Spring experience has grown). What I really like about Spring MVC is unlike Struts it is not overkill to use Spring MVC for very small applications.

The following is actually my second Spring MVC application (incidentally, my initial effort was to use JA-SIG CAS for authenticating XFire web services using WS-Security). This is a much simpler application and for regular readers of my blog (as if!) this will be familiar territory. This distribution makes use of Maven 2 (my favourite toy after Spring), using Maven 2 my whole distribution (17kb) is probably smaller than this web page!

I have written a single Spring MVC controller which returns an XsltView. What is special about this is that I use it to invoke XSLT 2 (Saxon again!). This results in an easy to install distribution of my previous IE7 emulator work. Using XSLT 2 with Spring MVC is actually incredibly easy.

Download IE7Emulator.zip -~17kb

All you need is to install Maven 2, download my distribution and run:

mvn compile war:war

and you are good to go! Enjoy!

2 comments:

ismjml said...

For me Spring MVC has the two of the same issues that Struts has, albeit not as bad. The first is too much config and the second is having the controllers bound to Http objects. Both of those reasons are why I switched to Stripes and haven't looked back. No XML config and the actions don't accept Http objects as parameters which makes unit testing even more easy to do.
Note: Comment imported. Original by Robert website: http://thebull.macsimumweb.com at 2007-10-23 16:57

ismjml said...

It may sound odd but I like XML configs.
Note: Comment imported. Original by markmc website: http://content.mark-mclaren.info/ at 2007-10-23 18:01