Struts 2 + Hibernate integration example
In Struts2, there are no official plugins to integrate the Hibernate
framework. But, you can workaround with the following steps :
- Register a custom ServletContextListener.
- In the ServletContextListener class, initialize the Hibernate session and store it into the servlet context.
- In action class, get the Hibernate session from the servlet context, and perform the Hibernate task as normal.
See the relationship :
Struts 2 <-- (Servlet Context) ---> Hibernate <-----> Database
In this tutorial, it shows a simple customer module (add and list function), developed in Struts 2, and perform the database operation with Hibernate. The integration part is using the above stated mechanism (store and retrieve the Hibernate session in the servlet context).
Struts + Spring + Hibernate integration example
In this tutorial, it shows the integration between “Struts2 + Spring + Hibernate“. Make sure you check the following tutorials before continue.
See the summary of integration steps :
- Get all the dependency libraries (a lot).
- Register Spring’s ContextLoaderListener to integrate Struts 2 and Spring.
- Use Spring’s LocalSessionFactoryBean to integrate Spring and Hibernate.
- Done, all connected.
See the relationship :
Struts 2 <-- (ContextLoaderListener) --> Spring <-- (LocalSessionFactoryBean) --> Hibernate
阅读(1709) | 评论(0) | 转发(0) |