Home  >  Article  >  Java  >  What is Spring framework

What is Spring framework

(*-*)浩
(*-*)浩Original
2019-05-06 10:45:5424048browse

Spring is an open source framework that was created by Rod Johnson and was created to solve the complexity of enterprise application development. Spring can use basic JavaBeans to complete things that were previously only possible by EJBs. .

What is Spring framework

This article will briefly introduce the functions and modules of the Spring framework. For specific usage, please see the recommended course: Java Tutorial.

Spring is an open source framework created by Rod Johnson. It was created to solve the complexities of enterprise application development. Spring uses basic JavaBeans to accomplish things that were previously only possible with EJBs. However, Spring's uses are not limited to server-side development. From the perspective of simplicity, testability, and loose coupling, any Java application Can benefit from Spring.

Spring is a lightweight inversion of control (IoC) and aspect-oriented (AOP) container framework.

Lightweight - Spring is lightweight in terms of both size and overhead. The complete Spring framework can be distributed in a JAR file with a size of just over 1MB. And Spring The processing overhead required is also negligible. Furthermore, Spring is non-intrusive: typically, objects in a Spring application do not depend on specific Spring classes.

Inversion of Control - Spring promotes loose coupling through a technique called Inversion of Control (IoC). When IoC is applied, other objects that an object depends on are passed passively. Pass it in instead of creating the object itself or finding dependent objects. You can think of IoC as the opposite of JNDI - instead of the object looking for dependencies from the container, the container actively passes the dependencies to the object when it is initialized without waiting for the object to request it.

Aspect-oriented - Spring provides rich support for aspect-oriented programming, allowing for cohesive development by separating the application's business logic from system-level services (such as auditing and transaction management) . Application objects only implement what they are supposed to do - complete business logic - nothing more. They are not responsible for (or even aware of) other system-level concerns, such as logging or transaction support.

Container - Spring contains and manages the configuration and lifecycle of application objects. It is a container in the sense that you can configure how each of your beans is created - based on a configurable prototype ( prototype), your bean can create a single instance or generate a new instance every time it is needed - and how they are related to each other. However, Spring should not be confused with traditional heavyweight EJB containers, which are often large, cumbersome, and difficult to use.

Framework - Spring can configure and combine simple components into complex applications. In Spring, application objects are composed declaratively, typically in an XML file.

Spring also provides many basic functions (transaction management, persistence framework integration, etc.), leaving the development of application logic to you.

All of these Spring features enable you to write code that is cleaner, more manageable, and easier to test. They also provide basic support for various modules in Spring.


The Spring framework consists of seven well-defined modules

What is Spring framework

Taken as a whole, these modules provide you with everything you need to develop enterprise applications. But you don't have to base your application entirely on the Spring framework. You are free to choose the app that suits you modules and ignore the rest.

As you can see, all Spring modules are built on top of the core container. The container defines how beans are created, configured and managed - more details in Spring.

You will potentially use these classes when you configure your application. But as a developer, you are most likely to be interested in other modules that affect the services provided by the container. These modules will Will provide you with a framework for building application services, such as AOP and persistence.

Core container

This is the most basic part of the Spring framework. It provides dependency injection (DependencyInjection) features to implement container management of beans. The most basic concept here is the BeanFactory, which is the core of any Spring application. BeanFactory is an implementation of the factory pattern that uses IoC to separate application configuration and dependency specifications from the actual application code.

Application context (Context) module

The BeanFactory of the core module makes Spring a container, and the context module makes it a framework. This module extends the concept of BeanFactory and adds support for international (I18N) messaging, event propagation, and verification support.

In addition, this module provides many enterprise services, such as email, JNDI access, EJB integration, remote and scheduling services. Also includes template boxes Frames such as Velocity and FreeMarker are integrated with support.

Spring’s AOP module

Spring provides rich support for aspect-oriented programming in its AOP module. This module is the basis for implementing aspect programming in Spring applications. In order to ensure that Spring and other AOP framework interoperability, Spring's AOP support is based on the API defined by the AOP Alliance. The AOP Alliance is an open source project whose goal is to promote the use of AOP and interoperability between different AOP implementations by defining a common set of interfaces and components. You can find out more about the AOP Alliance by visiting their site.

Spring’s AOP module also introduces metadata programming to Spring. Using Spring's metadata support, you can add annotations to your source code to indicate to Spring where and how How to apply the aspect function.

JDBC Abstraction and DAO Module

Using JDBC often results in a lot of repetitive code, obtaining the connection, creating the statement, processing the result set, and then closing the connection. Spring's JDBC and DAO modules extract these duplicate code code, so you can keep your database access code clean and concise, and you can prevent problems caused by failures to close database resources.

This module also builds a meaningful exception layer on top of the error messages given by several database servers. No more trying to decipher cryptic private SQL error messages!

In addition, this module also uses Spring's AOP module to provide transaction management services for objects in Spring applications.

Object/Relational Mapping Integrated Module

For those who prefer to use object/relational mapping tools instead of using JDBC directly, Spring provides an ORM module. Spring does not attempt to implement its own ORM solution Instead, it provides integration solutions for several popular ORM frameworks, including Hibernate, JDO, and iBATIS SQL mapping. Spring's transaction management supports each of these ORM frameworks including JDBC.

Spring's Web module

The Web context module is built on the application context module and provides a context suitable for Web applications. In addition, this module also provides some service-oriented support. Example

For example: implementing multipart requests for file uploads. It also provides integration of Spring and other Web frameworks, such as Struts and WebWork.

Spring's MVC framework

Spring provides a comprehensive MVC framework for building Web applications. Although Spring can be easily integrated with other MVC frameworks, such as Struts, Spring's MVC framework uses IoC to provide complete separation of control logic and business objects.

It also allows you to declaratively bind request parameters to your business objects. In addition, Spring's MVC framework can also take advantage of any of Spring's other services, such as internationalization information and validation.

Spring framework Web page garbled code problem

When doing java Web projects, garbled code problems often occur, and the solutions are also different, some are simple and some are complex; It will be different if you add the Spring framework, but We can use the CharacterEncodingFilter that comes with the Spring framework, which can greatly reduce our workload and is simple, convenient and easy to understand.

The above is the detailed content of What is Spring framework. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn