Spring Core Technology

Source: Internet
Author: User

This is the second time I read about Spring, because I learned from Spring while watching videos at the beginning, so I pay more attention to implementation code, but I still have insufficient grasp of the macro level, this time we mainly analyze Spring from a macro perspective.

What is Spring?

Spring is an all-in-one lightweight open-source framework for layered Java SE/EE applications. It uses IoC (Inverse of Control: inversion Control) and AOP (AspectOriented Programming: Aspect-Oriented Programming) as the kernel, provides enterprise-level application technologies such as Spring MVC at the presentation layer, Spring JDBC at the persistent layer, and transaction management at the business layer. In addition, spring integrates many third-party framework libraries in the Open Source world with the mind of Haina baichuan, and gradually becomes the most widely used open-source Java EE Enterprise Application Framework.

Benefits of Spring

First of all, to learn and use Spring, we must know the advantages of using Spring. If we cannot understand its advantages, we cannot use this framework as appropriate, of course, the meaning of learning is lost.

Easy structure and simplified development

Through the IoC container provided by Spring, we can control the dependency between objects by Spring to avoid excessive program coupling caused by hard programming. With Spring, you do not have to write code for underlying requirements such as single-instance mode and attribute file parsing, so you can focus more on upper-layer applications.

Support for AOP Encoding

With the AOP function provided by Spring, it is easy to implement Aspect-Oriented Programming. Many features that are not easy to use and implemented by traditional OOP can be easily handled through AOP.

Support for declarative transactions

In Spring, we can free ourselves from the boring fifteen Management Code and flexibly manage transactions in declarative mode to improve development efficiency and quality.

Convenient program testing

Almost all testing work can be performed using non-container programming methods. In Spring, testing is no longer an expensive operation, but an easy task to do.

Easy integration of various excellent frameworks

Spring does not exclude all kinds of excellent open-source frameworks. On the contrary, Spring can reduce the difficulty of using various frameworks. Spring provides various excellent frameworks (such as Struts, Hibernate, Hessian, and Quartz).

Reduces the difficulty of using Java EE APIs

Spring provides a thin encapsulation layer for many difficult Java EE APIs (such as JDBC, JavaMail, and remote calls) through Spring's simple encapsulation, the difficulty of using these Java ee apis is greatly reduced.

Java source code is a classic learning example

The source code design of Spring is exquisite, clear in structure, and ingenious. It reflects the Masters' flexible use of Java design patterns and their profound accomplishments in Java, the Spring framework source code is undoubtedly an example of the best practices of Java technology. If you want to quickly improve your Java technology and application development level within a period of time, learning and studying Spring source code will bring you unexpected results.

Architecture of Spring

If Spring is a person, AOP and IoC are his soul (AOP and IoC have been mentioned in the previous blog), and his structural system is his skeleton. Therefore, here we need to study in detail the structure system of Spring.

A picture is better than a thousand words


The following describes the content of each module in the struct.

Core container:

The core of the core container is Beans, context, and expression language modules. The main functions of each module are as follows:

The core module of spring implements the IOC function, which disconnects the dependencies between classes from the code and describes the Dependencies by configuration, the loc container is responsible for creating, splicing, managing, and obtaining dependent classes,BeanFactoryInterfaces are the core interfaces of the Spring framework. They implement many core functions of containers.

ContextBuilt on the core module, the BeanFactory function is extended and multiple functions such as i18n internationalization, Bean lifecycle control, framework Event System, and transparent resource loading are added. In addition, this module also provides support for many enterprise-level services, such as mail service, task scheduling, JNDI positioning, EJB integration, and remote access.

ApplicationContext is the core interface of the Context module.

Expression Language ModuleIt is an extension of the unified Expression Language (uniied EL). It is used to query and manage objects in runtime. It supports setting and obtaining object attributes, calling object methods, Operation arrays, and collections. It also provides functions such as logical expression operations and variable definitions. With this function, you can easily interact with the Spring IOC container through expression strings.

Data Access/integration:

The Data Access/integration layer includes JDBC, ORM, OXM, JMS, and transaction processing modules. The functions of each template are as follows:

JDBCThe module provides an abstraction layer related to JDBC that no longer requires lengthy JDBC encoding.

ORMThe integration layer provided by the module. Popular object link ing APIs, including JPA, JDO, Hibernate, and iBatis.

OXMThe module provides an abstraction layer that supports object/XML ing for JAXB, Castor, using XMLBeans, JiBX, and XStream.

Java Message ServiceJMSThe module contains production and consumption information.

The transaction module supports programming and Clear transaction management to implement special interface classes for all POJO.

The core issue of any application is Data Access and operations. There are many forms of data, such as data tables, XML, and messages. Each type of data has different data access technologies (for example, data table access can be directly performed through JDBC, you can also use Hirnate or iBatis ).

At the abstract level of DAO, Spring has established a unified exception system for DAO layer. At the same time, it converts the checked exceptions of various access data into non-checked exceptions, it provides the foundation for integrating various persistent layer frameworks. Second, Spnng uses templated technology to encapsulate various data access technologies in a thin layer, hiding the modeled code, and greatly simplifying the Data Access Program, spring has established a uniform DAO layer unrelated to data forms and access technologies. With the help of AOP technology, Sp blood g provides declarative transaction functions.

Web:

The Web layer includes the network, Web-Servlet, Web-Struts, and network Portlet components. The details are as follows:

WebThe module provides basic Web development integration features, such as the multiparty file upload function and the IoC container initialization of servlet listeners and the Web application context.

Web-ServletThe module contains Spring Model-View-controller (MVC) to implement Web applications.

Web-StrutsThe module contains Spring applications in the Support class that integrate the classic StrutsWeb layer. Yiibai.com

Web-PortletThe module provides the functions of MVC to implement Servlet modules used in the portlet environment and mirror Web. Yiibai.com

This module is built on the ApplicationContext module and provides various tool classes for Web applications, such as initializing Spring containers through Listener or Servlet, and registering Sprmg containers to Web containers. This module also provides multiple web-oriented functions, such as transparent file upload, Velocity, FreeMarker, and XSLT.

In addition, Spring can integrate Struts, WebWork, TapestryWeb and other MVC frameworks.

Others:

There are also some important modules such as AOP, aspect, specification, network and test module. Their details are as follows:

The AOP module provides Aspect-Oriented Programming implementation that allows you to define method interceptors and entry points to clean decoupling and implement functions that should be separated by code.

The Aspects module provides integration with AspectJ, which is a powerful and mature Aspect-oriented programming (AOP) framework.

The Instrumentation module provides support for class tools and class loaders in certain application servers.

The test module allows Spring components to use the JUnit or TestNG framework for testing.


In addition, Spring provides integration with many well-known frameworks in remote access and WebService. Due to the scalability of the Spring framework, especially with the expansion of the influence of the spring framework, more and more frameworks are actively supporting the Spring framework, making the application of the spring framework wider and wider.


This blog draws on Spring3.X enterprise development and application practices. It is a very systematic book on Spring. I suggest you take a look.

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.