[It168 technical documents] http://tech.it168.com/j/2007-08-02/200708022255218.shtml
This articleArticleThis is a summary after I read Xia Xin's spring guide again. I am most familiar with Struts, but I do not have much practical experience with spring and hibernate. So although this article focuses on the integration of the three, it is mainly centered on struts.
First, let's take a look at the integration of struts and spring.
First take a look at the need to make changes in the struts-config.xml, the first is to add the plug-in Declaration:
<Struts-config>
<Plug-in
Classname = "org. springframework. Web. Struts. contextloaderplugin">
<Set-Property = "contextconfiglocation"
Value = "/WEB-INF/applicationcontext. xml"/>
</Plug-in>
</Struts-config>
Another part that needs to be changed in the struts configuration file is its actionmapping part, which will be discussed later.
In fact, adding spring to struts is not very complicated. The most important thing is that we need to know whether the system requires spring, that is to say, whether the so-called dependency injection and other features of spring have a greater significance for development than the development cost after spring is used.
The following figure illustrates the combination of struts and spring.ProgramBasic Process:
As shown above, the most important thing for struts to integrate with spring is to change the action-mapping settings in the struts-config.xml and spring gets control before entering the action of struts.
Let's talk about the integration of spring and struts.
The integration of struts and Hibernate is not very complex. I have summarized the following points:
1. Hibernate-Context.xml
The sessionfactory attribute needs to be set in the <bean> item of this file. Spring has integrated sessionfactory settings, so it does not need to be set again in hibernate. cfg. xml. You can also set the list of ing files. HBM. xml.
2. Dao inherits hibernatedaosupport to call its Function
Hibnernatedaosupport associates hibernatetemplate with sessionfactory. Hibernatetemplate (obtained using gethibernatetemplate () in hibnernatedaosupport) encapsulates hibernate sessions, saving you from a series of steps such as session instance acquisition, transaction startup, commit/rollback, and exception handling, so it is very simple.
The integration of struts, spring, and Hibernate is discussed in the above two aspects. Finally, the following is a brief summary:
By modifying the struts configuration file, spring can gain control over the action in struts, and also add spring features to struts. Combined with hibernate, the above spring features are used to simplify database operations.