At Rivet Logic we do quite a bit of work with the JBoss Seam framework, specifically with our Content Management System integration we call Crafter rivet.
Seam can be used with the Spring bean factory framework, a popular “IoC” or Inversion of Control / Dependency injection framework. Spring enables developers to create instances of java objects known as beans and then to wire them to other java objects. Most people working in J2EE today are familiar with this so I won’t spend any time going in to further detail here. Seam also supports the ability to use java annotations to declare a class as a bean and to specify how it should be wired through what they call out-jection and injection. Check out the Seam website for more details on how the Seam bi-jection mechanics work.
One question that has come up for me many times on consulting engagements is: “which approach to use, Spring or Seam bi-jection?” My experience shows me that the answer is not one or the other. Both approaches have significant benefits and can be used together to create a stronger approach than either one can provide on its own.
Here are some very simple guidelines
When to use Spring beans:
Infrastructure components and services are great candidates for Spring beans
- Such services are generally singletons within the system. Spring has excellent support for managing and wiring these objects
- Such service classes are often packaged in separate more commonly used libraries. Hard coding a bean name and wiring within the class definition or strongly coupling to Seam is less desireable.
- You want a very simple way to override the implementation at deployment time. Consider a scenario where you want to override a DAO. By managing the bean in Spring it is extremely easy to override the bean definition to use an alternate class and configuration in a given environment simply by placing an additional xml file in the classpath
When to use Seam annotations:
Domain specific components are good candidates for bi-jection.
- They are often fine grained application specific components.
- Explicitly stating how the component will be wired in the the class file has little impact on its re-usability because its scope is limited to the application at hand.
- Such components really benefit from one of Seams strongest features in its bean framework: Conversation Scoping. This is the ability to define a life-cycle which is shorter than a session. By limiting the lifetime of a object to its true life-cycle it’s possible to free memory up for other needs within the system. On large, high troughput applications the benefits here cannot be overstated.
By using a combined approach you get the reusability and flexibility of Spring framework with the performance orientation of conversation scoping and ease of development associated with Seam annotations.