Why use spring, (and three framework profiles)

Source: Internet
Author: User

Spring as one of the three big frames, has been puzzled what is her use? Why use Spring? (most of them are from the Internet, citing too many sources, not to be identified.) )。

SSH represents 3 frameworks in the Java EE Project, Spring + Struts +hibernate. Struts provides the corresponding components for both Model,view and controller. Spring is a lightweight control inversion (IoC) and facet-oriented (AOP) container framework that is created by Rod Johnson. It is created to address the complexities of enterprise application development. Spring uses basic JavaBean to accomplish things that were previously only possible by EJBS. Hibernate is an open source object-relational mapping framework that provides JDBC with a very lightweight object encapsulation that can be used in any JDBC application, in servlet/jsp Web applications, or in the Java EE architecture of the EJB application to replace the CMP To complete the task of data persistence.
The STRUTS2 principle is to use interceptors so that requests sent by your clients are intercepted and processed. The interceptor is in the reflection mechanism. The main function of STRUTS2 is control forwarding, which is the handling of the action, and the Struts.xml configuration.
Spring actually contains a lot of knowledge, with IOC,AOP and so on, is actually a management framework of the container, you do not have to consider your new object, it will help you do, reduce the layer and layer coupling degree. Spring has a lot of ideas, the IOC is control inversion, injected. AOP is facet-oriented and a bit like an interceptor.
Hibernate is a persistent layer framework, we usually use the JDBC database to write SQL statements, and sometimes a lot of fields will be very troublesome, so with hibernate is very convenient, you just master the mapping inside the relationship, you do not have to write SQL statements, it will help you write, API call is very convenient.

The

Struts
1.Struts frame structure

Struts provides the corresponding components for both Model,view and controller.
in the image on the right, Actionservlet, the class is the core controller of struts, which intercepts requests from users. The
Action, which is typically provided by the user, is responsible for receiving a request from Actionservlet and invoking the model's business logic method to process the request based on that request, and returns the processing result to the JSP page display. The
2.Model section consists of Actionform and JavaBean, where actionform is used to encapsulate the user's request parameters, encapsulated as a Actionform object, which is forwarded to the action by Actionservlet, The action processes the user's request based on the request parameters inside the Actionform. The
JavaBean encapsulates the underlying business logic, including database access. The
3.View section uses JSP implementations.
Struts provides a rich library of tags that can reduce the use of scripts through a tag library, and a custom tag library enables effective interaction with the model and adds real-world functionality. The corresponding JSP part. The
4.Controller Component Controller component consists of two parts-the system core controller, the business logic controller. The
System core controller, corresponding to the Actionservlet. The controller is provided by the struts framework and inherits the HttpServlet class, so it can be configured as a callout servlet. The controller is responsible for intercepting all HTTP requests and then deciding whether to transfer to the business logic controller based on user requests. The
Business logic controller, which handles user requests, does not have the processing power in itself, but instead calls model to complete processing. Corresponds to the action section.

Spring
1. Introduction
Purpose: Solve the complexity of enterprise application development
Function: Use basic JavaBean instead of EJB and provide more enterprise application functions
Scope: Any Java application
simply, Spring is a lightweight control inversion (IoC) and facet-oriented (AOP) container Framework .
2. Spring is lightweight, both in terms of size and overhead. The full spring framework can be published in a jar file with a size of more than 1MB. and the processing overhead required by spring is negligible. In addition, spring is non-intrusive: Typically, objects in spring applications do not depend on a particular class of spring.
3. Control reversal Spring facilitates loose coupling through a technique called inversion of Control (IoC). When an IOC is applied, other objects that an object relies on are passed in passively, rather than the object itself creating or locating dependent objects. You can think of the IOC as opposed to Jndi--not the object looking for dependencies from the container, but the container actively passing the dependency to it when the object is initialized without waiting for the object to be requested.
4. Faceted spring provides rich support for aspect-oriented programming, allowing for the development of cohesion through the separation of application business logic with system-level services such as auditing (auditing) and transaction (transaction) management. The Application object only implements what they should do-complete the business logic-that's all. They are not responsible (or even conscious) for other system-level concerns, such as log or transaction support.
5. Container Spring contains and manages the configuration and lifecycle of the Application object, in this sense it is a container where you can configure how each of your beans is created-based on a configurable prototype (prototype), Your bean can create a separate instance or generate a new instance each time it is needed-and how they relate to each other. However, spring should not be confused with traditional heavyweight ejb containers, which are often bulky and cumbersome and difficult to use.
6. Framework Spring can configure and combine simple components into complex applications. In spring, application objects are combined declaratively, typically in an XML file. Spring also provides a number of basic functions (transaction management, persistence framework integration, etc.), leaving the development of application logic to you.
All of these features of spring enable you to write cleaner, more manageable, and easier-to-test code. They also provide basic support for the various modules in spring.

Hibernate
1. Introduction
Hibernate is aOpen Source Object-relational mapping framework, it has a very lightweight object encapsulation of JDBC, allowing Java programmers to manipulate the database at will using object programming thinking. Hibernate can be applied to any JDBC application, both in Java client applications and in servlet/jsp Web applications, and most revolutionary of all, hibernate can replace CMP in the EE architecture of the EJB application. The task of achieving data persistence.
Hibernate has a total of 5 core interfaces: Session, sessionfactory, Transaction, query, and configuration. These 5 core interfaces will be used in any development. Through these interfaces, you can not only access persistent objects, but also enable transaction control. These five core interfaces are described separately below.
The 2.Session interface session interface is responsible for performing crud operations on persisted objects (the task of crud is to complete the communication with the database, including many common SQL statements. )。 However, it is important to note that the session object is non-thread-safe. At the same time, Hibernate's session differs from the HttpSession in JSP applications. When the term "session" is used, it is actually referring to the session in Hibernate, and later the Httpsesion object is called the user session.
The 3.SessionFactory interface Sessionfactory interface is responsible for initializing hibernate. It acts as a proxy for the data storage source and is responsible for creating session objects. The factory model is used here. It is important to note that Sessionfactory is not lightweight, because in general, a project typically requires only one sessionfactory, and when you need to manipulate multiple databases, you can specify a sessionfactory for each database.
The 4.Configuration interface Configuration interface is responsible for configuring and starting hibernate to create Sessionfactory objects. During Hibernate startup, the instance of the configuration class first locates the map document location, reads the configuration, and then creates the Sessionfactory object.
The 5.Transaction interface transaction interface is responsible for transaction-related operations. It is optional, and developers can also design their own underlying transaction-processing code.
The 6.Query and Criteria interface query and criteria interfaces are responsible for executing various database queries. It can be expressed in either the HQL language or the SQL statement.

Why use spring, (and three framework profiles)

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.