What role does spring play in the SSH framework?

Source: Internet
Author: User
Tags aop exception handling rollback ssh

It programmer development Essentials-all kinds of resources download list, history of the most IT resources, personal collection summary.

Spring acts as the role of the management container in the SSH box fake. We all know that Hibernate is used to make the persistence layer, because it makes JDBC a good package, programmers can not write a large number of SQL statements when interacting with the database. Struts is used to make the application layer, and he is responsible for invoking the business logic serivce layer. So the process of the SSH framework is basically: JSP page----STRUTS------service (Business logic processing Class)---Hibernate (left to right) Struts is responsible for controlling the service (Business logic processing Class), thus controlling the Servic The life cycle of e, so that layers and layers of dependence is strong, belong to the coupling. At this point, the spring framework is used to control the action object (in Strus) and the Service class, and the relationship between the two is loose, and spring's Ioc mechanism (control inversion and dependency injection) is used here.

Spring's IOC(control inversion and dependency injection)

control reversal: It is the (dependency) relationship between the container control program, not the traditional implementation, directly manipulated by the program code

Dependency Injection: dependencies between components are determined by the container at run time, and the container dynamically injects some kind of dependency into the component.

the second benefit of using spring (AOP application):

Handling of transactions:

In previous JdbcTemplate, the transaction was submitted successfully, and exception handling was done through Try/catch, and in spring. The spring container integrates transactiontemplate, which encapsulates all the functionality of transactional processing, including complex business functions such as transaction rollback during an exception, data submission when the operation succeeds. This is managed by the spring container, greatly reducing the amount of code for the programmer, and also has good administrative control over the transaction. Hibernate also has the management of transactions, hibernate in the transaction management is through the Sessionfactory creation and maintenance session to complete. Spring also integrates the Sessionfactory configuration without having to set the sessionafactory through Hibernate.cfg.xml. This will make good use of sping for transaction management. It avoids the need to get the session instance to start the transaction/COMMIT/ROLLBACK TRANSACTION and the tedious Try/catch operation for each data operation. These are good applications for the AOP (aspect-oriented programming) mechanism in spring. On the one hand, the development of business logic clearer, professional division of labor more easily. On the other hand, the application of SPIRNG AOP isolation reduces the coupling of the program so that we can combine the facets in different applications and greatly improve code reuse.

Achieve loose coupling

1 To add a housekeeper to your project, you don't have to write a lot of code to implement some of the features that the framework has already implemented. A lot of things can be done to the housekeeper.

A lot of interception, filtering, logging, internationalization issues, sending messages, integrated hibernate,ibatis,http remote calls. MVC framework and so on.

Transaction management, etc., do not need to write many of their own code, can be properly configured to the spring to manage.

Project development progress will be much faster. Once the schema is set up, the programmer is only responsible for implementing very few parts of the code to accomplish complex functions.


What is the role of struts hibernate spring in SSH?

For Struts control
Hibernate operations database.
Spring uses a decoupled


to say in detail
STRUTS in the SSH framework to play the role of control, the core is the controller, that is, Actionservlet, and the core of Actionservlet is Struts-confi g.xml. The main control of the processing of logical relationships.

Hibernate is a data persistence layer, a new mapping tool for objects and relationships, provides a mapping from Java classes to data tables, and provides mechanisms for querying and recovering data, which greatly reduces the complexity of data access. The direct operation of the database is converted to the operation of the persisted object.

SPRING is a lightweight control inversion (IoC) and facet-oriented (AOP) container framework, interface-oriented programming, and (dependency) relationships between container control programs, rather than traditional implementations, directly manipulated by program code. This is the concept of the so-called "inversion of Control": (dependency) control is transferred from the application code to the external container, and the transfer of control is called inversion. Dependency injection, in which the dependencies between components are determined by the container at run time, the image is that the container dynamically injects some kind of dependency into the component
The main function is to decouple


The role of Struts, spring and Hibernate in each layer

1 struts is responsible for the Web tier.

Actionformbean receives the data submitted by the form in the Web page, then processes it through the Action and Forward it to the corresponding page.

The <ACTION-MAPPING&GT is defined in Struts-config.xml, and Actionservlet is loaded.

2 Spring is responsible for business layer management, i.e. service (or manager).

(1. The service provides a statistical calling interface for the action, encapsulating the DAO for the persistence layer.

(2. Can write some of their own business methods.

(3. A unified approach to JavaBean management

(4. Declarative transaction Management

(5. Integrated Hiberante

3 Hiberante, responsible for persistence layer, complete crud operation of database
Hibernate is a persistent layer that provides or/mapping.
It has a set of. hbm.xml files and POJO that correspond to the tables in the database. Then you define DAO, which is the class that deals with the database, and they use the PO.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.