Integrating Spring into your application adds a lot of advantages like better modularity, great flexibility for developers, perfect testability of your code etc. Integrating Spring into JSF also adds cool possibilities for developers like usage of Spring AOP in backing beans or security checks for backing bean methods with usage of "spring-security".

Background information
This integration is developed for Backbase JSF Edition 4.2.0. JSF is used as as "view" technology and Spring is used as a "service" layer. The integration uses "VariableResolver" mechanism introduced in JSF 1.1. Just to clarify: the Spring example bundled with Enterprise Ajax 4.2.0 (spring_2_0.war) uses Spring MVC as "view" technology, not JSF.
1. Add Libraries to Classpath
First of all we have to add the Spring libraries to our application's classpath. As base we use the "blank" demo application from the "Backbase JSF Edition 4.2.0" distribution. Let's add the following jars from the Spring 2.5.3 distribution into our "WEB-INF/lib" folder:
- spring-beans.jar
- spring-context.jar
- spring-core.jar
- spring-web.jar
2. Define Listeners and Context Parameters
Next we need to define additional listeners and context parameters to "web.xml":
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
Here we introduced a listener which will create Spring's root WebApplicationContext.
<listener-class>
org.springframework.web.context.request.RequestContextListener
</listener-class>
</listener>
We also introduced a second new listener which exposes the request to the current thread.
Also if your Spring beans are defined in a file different from "/WEB-INF/applicationContext.xml" you should specify them in the "contextConfigLocation" context parameter like this:
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/backingBeanContext.xml /WEB-INF/applicationContext.xml</param-value>
</context-param>
This parameter is used by "ContextLoaderListener" to load bean definitions.
3. Define Backing Beans
Also we need to create the "applicationContext.xml" file which will contain our backing bean definitions:
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
<a href="http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">" title="http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">">http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"></a>
<bean id="sampleBackingBean"
class="com.backbase.bjsf.example.SampleBackingBean"
scope="session"/>
</beans>
4. Update faces-config.xml
In our simple example we only have one backing bean "com.backbase.bjsf.example.SampleBackingBean" which we added in the "session" scope. Note you have to use the same values for backing bean IDs as when you use them in JSP (so as you had their names defined in "faces-config.xml"). As result we can comment out our backing beans from faces-config.xml.
Wrap-up
That's all. Let's deploy our web application to a web container and see that all works ok. If you have any questions or suggestions, please leave a comment below.

Comments
Hi,
29 April, 2008 - 15:15 — dizzyHi,
I think something is missing from your post - you have to delegate the variable resolver to Spring so the JSF backing beans be in fact Spring beans.
This can be accomplished by specifying something like
<variable-resolver>org.springframework.web.jsf.DelegatingVariableResolver</variable-resolver>
</application>
in the faces-config.xml file
Cheers,
George
Re: Hi
4 May, 2008 - 05:50 — v_peterHi, George,
Many thanks for your comment. You are completely right I forgot to mention it.
Thank you for your help,
Peter