Bens Stuff

Friday, July 09, 2004

Spring things

I was googling something about lightweight remoting of Hessian and Burlap (after reading this article) and found this wonderful post on Javaranch about Spring. It's cleared some things up for me.

Here is a quick overview of the various parts of Spring...

Spring-AOP
Spring includes a full AOP implementation (that uses Dynamic Proxies or CGLIB). Unfortunately, the mistake that most people make is in understanding the goals for Spring-AOP. It was not really intended for use on a fine-grain level compared other AOP Frameworks like AspectJ, AspectWerkz, Nanning, or DynAOP. The Spring developers are even quick to point out that if you want to do fine-grained AOP then you are probably better off using a solution like AspectJ. The Spring-AOP solution is really intended to be used to provide enterprise services such as resource pooling and transactioning. In fact, if you are just interested in these services then you don't have to directly use the Spring-AOP code at all. In general, I would say the average Spring using won't directly touch AOP.

Spring-IoC
This is where a lot of the magic that is Spring takes place. Like PicoContainer, Spring supports both Constructor Dependency Injection and Setter Dependency Injection. One of the most complex parts of writing any application is managing dependencies. We go to great lengths to create layer upon layer of indirection in an attempt to keep our code as decoupled as possible. Of course, the benefits to decoupled code speak for themselves and Spring-IoC makes this task almost painless. In fact, most of Spring's power and flexibility comes as a direct result from its IoC implementation.

Spring-Transaction Management
This is one of those areas of Spring that really shines. One of the primarily motivations of using EJB, as I mention here, is and has always been declarative transaction management. In particular, the use of JTA to manage global transactions across multiple transactional resources. Spring allows the use of declarative transaction management without an EJB Container for both local and global transactions. It doesn't matter if you are using plain JDBC, JTA, Hibernate, or JDO your transaction management stays the same.

Spring-DAO
If you are still doing straight JDBC (which I know you are with Jenny) then you need to look into this package. Spring-DAO greater simplifies writing JDBC code, all of the mundane setup work that goes into writing JDBC code is abstracted away. All the resource handling is done automatically for the developer so there is no chance of forgetting to close a Connection, Statement, or ResultSet anymore. Spring-DAO handles all of the basic flow like statement creation and execution and leaves the developer to extract the results. Spring-DAO even provides a nice consistent set of Exceptions for all data access.

Spring-ORM
Spring provides a nice abstraction layer on top of Hibernate, JDO, and iBATIS. Spring ORM managing many of the low-level details such as Session management in Hibernate and PersistenceManager management in JDO. Add in the nice consistent Spring-DAO Exception Hierarchy and Spring's declarative transactioning and you get a really powerful alternative to CMP.

Spring-EJB
Just so you don't get the wrong impression, Spring also supports EJB in the form of convenient superclasses and a transparent access API. When using Spring-EJB your client doesn't need to have any knowledge of EJB or perform any JNDI lookups.

Spring-Other
In addition of the above, Spring also has numerous other miscellaneous features. These include APIs for JNDI, Job Scheduling (using Quartz), Remoting (using RMI, JAX-RPC, Hessian, or Burlap), JavaMail, even a full MVC Framework, and more. Like I said, Spring is very comprehensive, there is something for everyone.


At some point I'm going to convert our old MVC framework to use either Spring, Struts, WebWork, or Tapestry. But that's another post for another day :)