There are advantages and disadvantages to choosing Spring or Seam for developing an application. The third option is to use both of them and leverage the best of both frameworks. If Spring and Seam are integrated then they can pass components to each other to use depending on which framework can construct that component in the best possible way. The instructions below are based on Seam 2.2.0.GA and Spring 3.0.0.
In order to integrate Spring into Seam, you need the ability to start up both of the containers and allow them access to each others components. To assist with this Seam provides a special ContextLoader in the jboss-seam-ioc jar file, so that Seam can read the Spring configuration files and start up the Spring container. To configure this you need to edit Seam’s components.xml and add the following namespace and schema entry:
Further down the file within the components section you instruct Seam to bootstrap the Spring container, assuming by default that there is a WEB-INF/applicationContext.xml containing the Spring configuration.
You then add a basic applicationContext.xml
Any additional spring configuration will be added to this file.
For this code to work, you need to add the following jar files to your ear file. The jboss-seam-ioc.jar contains the classes that allow you to integrate Spring and the other jars are required for the Spring configuration files.
You can now add a spring bean into your applicationContext.xml
You will obviously need to create a corresponding class for this bean. The seam:component tag marks this bean as a SpringComponent which is registered for use as a Seam component by the Seam container.
You can now inject the bean into another class as a seam component.
private ExampleSpringBean exampleSpringBean;
String value = exampleSpringBean.getTestString();
This is a very simple example with basic configuration that doesn't take into account any of the issues you may need to watch out for when mixing Spring and Seam.