Spring configuration tips

So, we decided to use Spring framework… here comes hell !

Without a little management, spring configuration files grow quite fast and may soon become hard to maintain.

Craig Walls’s offers us some spring best-pratices in his excellent Spring-cleaning presentation (pdf).

Another good source is the SpringTips blog that offers us 12 best-practices for spring xml configuration.

To Spring or not ?

I have been spending last weeks defining the architecture of a new web application.

The main driver is to rely on a MDA (Model driven architecture) to generate the major part of the application code thanks to Acceleo . We build custom template files that are converted to a fully working application via acceleo generators.

A proof of concept:

The first versions of this project was developped as a Struts 1 webapp on top of hibernate ORM. The choice of Struts was mainly driven by the fact that the team new this framework quite well … and that we had exmples of code available for it. So we ended up developing our struts-specific templates files to generate the views and controllers of the application.

Spring time has come !

It’s now time to “industrialize” this first version. The main constraint is that we keep what has been developed for Struts. But we also need to implement new functionnality (integration with LDAP, data synchronization with other applications, audit logging, exposition of webservices….).I start to feel that Struts (especialy 1.x) is pretty limited and wil force us to develop modules that could be found out of the box in other Frameworks.

From other projects, I retain that Spring is a very modularized framework, that can be used “on demand”, to provide from basic services to full web application framework.

Why Spring ?

  • we reuse 99% of our existing truts code. By using the dynamic proxies of Spring, we can rely on AOP to add functionnality to our code (the detailled method (IBM)).
  • forces a better modularity of code
  • … that strongly encourages (and ease) unit testing.
  • allows us to modularize the application itself.
  • simplify integration with external systems (mail, LDAP) by providing easy to use templates.

Why not ?

  • Spring configuration files might become complex as they grow.. but we generate them.
  • and… is that all ?

Ressources

It was quite hard to find arguments against Spring, so I will list pro-spring resources here (comments welcome !).