JSF 2, Spring 4, Hibernate 4 and Maven Integration

In this tutorial I will show you how to integrate JSF 2, Spring 4, Hibernate 4 and Maven. In the previous example Spring 3, JSF 2 and Hibernate 3 integration example , I have shown how to integrate JSF 2, Spring 3 and Hibernate 3 but I have not used maven there.

For this tutorial we will create maven based web project in Eclipse.

If you already have an idea on how to create a maven project in Eclipse will be great otherwise I will tell you here how to create a maven project in Eclipse.


The following configurations are required in order to run the application

Eclipse Kepler
JDK 1.8
Tomcat 8
Have maven installed and configured
JSF 2, Spring 4, Hibernate 4 dependencies in pom.xml

Now we will see the below steps how to create a maven based project in Eclipse
Step 1. Create a maven based web project in Eclipse

Go to File -> New -> Other. On popup window under Maven select Maven Project. Then click on Next. Select the workspace location – either default or browse the location. Click on Next. Now in next window select the row as highlighted from the below list of archtypes and click on Next button.


Now enter the required fields (Group Id, Artifact Id) as shown below

Group Id : com.roytuts
Artifact Id : jsf-spring-hibernate

The created project looks like below

jsf spring hibernate

Step 2. Modify the pom.xml file as shown below.

Step 3. If you see JRE System Library[J2SE-1.5] then change the version by below process

Do right-click on the project and go to Build -> Configure build path, under Libraries tab click on JRE System Library[J2SE-1.5], click on Edit button and select the appropriate jdk 1.8 from the next window. Click on Finish then Ok.

Change also the Compiler compliance level as 1.8 from Java -> Compiler.

Step 4. Now when the build process finished then modify the web.xml file with below source code

Step 5. Create spring-config.xml file under WEB-INF directory with the below source code

Step 6. Create hibernate.cfg.xml file under WEB-INF directory

Step 7. Create faces-config.xml file under WEB-INF directory. <el-resolver/> is required to resolve spring beans from JSF managed beans.

Step 8. Create MySQL table user_details in database cdcol

Step 9. Dump some data into the table

Step 10. Now create Entity bean class which will map Java object to database table user_details

Step 11. Create DAO interface for querying database table

Step 12. Create the corresponding DAO implementation class

Step 13. Create the service interface for processing logic or business logic

Step 14. Create the corresponding service implementation class

Step 15. Create JSF 2 managed bean which will handle user request and response

Step 16. Now create user.xhtml file for displaying single user details

Step 17. Create listUsers.xhtml file for displaying all users details

Step 18. Now run the application on Tomcat server 8 and when the application successfully deployed onto the server, please hit the URL http://localhost:8080/jsf-spring-hibernate/listUsers.jsf , you will below output in the browser

jsf spring hibernate

The corresponding console output

When you hit the URL http://localhost:8080/jsf-spring-hibernate/user.jsf in the browser, you will see the below output

jsf spring hibernate

The corresponding console output

Thanks for reading.


Software Professional, I am passionate to work on web/enterprise application. For more information please go to about me. You can follow on Twitter. You can be a friend on Facebook or Google Plus or Linkedin

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.