Describe the design concept of spring containers

Source: Internet
Author: User

 

Overview

Spring is an open-source framework created to solve the complexity of enterprise application development. Spring books on the bookstore are full of resources, and many articles related to the Internet are well written, there are examples of getting started, solutions for problems, environment settings, source code analysis, and integration of spring with other open source systems. This article introduces the macro Design Concept of spring containers through examples in terms of spring source code and terminology.

Let the spring container go down the altar

Spring containers provide the basic functions of the Spring framework and are implemented in the factory mode. In other words, spring is the Bean factory that manages the bean lifecycle. So how to design it? Although the source code of spring is not so powerful, it is also dizzy, as shown in, we let the spring container go down the altar. Since it is for interface programming, we use interfaces to describe the framework, it is unnecessary to stick to the specific implementation, which may be clearer.

Any design is like this. There are raw materials, portals, processes, and outlets. Since spring is the bean container and Bean factory, the bean production process is:

1)
Raw Material: bean configuration file

2)
Feed: Read XML text files through resourceloader

3)
Initial Processing: raw materials are processed into semi-finished products through beandefinitionreader beandefinition

4)
Finishing: beanfactory in bean production workshop processes beandefinition, a semi-finished product, into Bean

5)
Warehouse receiving: the finished product library singletonregistry stores the finished bean and the bean tag (beanid! You also know that this is the work of map.

 

 

 

Is IOC the core of sprng? Key?

Spring containers use the IOC mode to separate application configuration and dependency specifications from the actual application code. The IOC mode is the basic principle based on Java reflection.

In general software design, IOC must be the core of the container. Other peripheral functions such as bean scope are based on IOC, while spring design only places it as a Tool class beanutil, this is precisely what makes spring better. Although IOC is the basis for spring to create beans, it is necessary to determine whether a bean is created in a static factory and whether there is a construction method containing parameters, these parameters may also be instances of other objects and bean initialization methods. These parameters are not only covered by bean IOC, in addition, you may need to call the IOC program multiple times during bean creation.

To sum up, although IOC is the basic principle for spring bean creation, it is only an important part and is not the core of spring containers, is an indispensable tool for spring to create beans. IOC is the key to spring containers, not the core.

Hierarchical Interface Design

The hierarchical design of interfaces provides different levels of products for different customers. Different levels of interface focus on different levels, just as the product is also divided into multiple levels, such as advanced products, intermediate products, and primary products correspond to different customer groups, or the bank's customer channels include bank cards, counters, online banking, mobile terminals, and ATMs. Likewise, interfaces can be divided into internal interfaces and external interfaces, just as some interfaces may never be known to external users. They are only used internally, just like internal products between multiple workshops in the factory.

Org. springframework. Beans. Factory. beanfactory is the top-level interface of spring. Only the getbean series, containsbean, isprototype, issingleton, GetType, and other basic methods for finished bean.

Org. springframework. Beans. Factory. listablebeanfactory is a factory management method, such as containsbeandefinition, getbeandefinitioncount, delimiter, getbeannamesfortype series, getbeansoftype series, and listablebeanfactory is for beandefinition.

The applicationcontext interface not only integrates the listablebeanfactory interface, but also inherits the functions of resourcepatternresolver, hierarchicalbeanfactory, applicationeventpublisher, and messagesource, such as resource processing (International processing) and event transmission, and context implementation between application layers. This is also the external interface. Spring also recommends applicationcontext because applicationcontext is more like a product for VIP customers.

 

 

 

 

 

Interface extension Design

Spring design is an open design concept and is worth learning by our architects, as shown in:

Com. springframework. Beans. Factory

(Pale yellow background)

| Beanfactory

| Listablebeanfactory

| Configrablelistablebeanfactory

| Defaultlistablebeanfactory

 

 

Com. springframework. Context

(Brown-red background)

Applicationcontext

Configrableapplicationcontext

 

 

Org. springframework. Context

(Yellow background)

. Support

Abstractapplicationcontext

Abstractrefreshableapplicationcontext

Abstractxmlapplicationcontext

Classpathxmlapplicationcontext

 

Org. springframework. Web. Context

(Green background)

Webapplicationcontext

Configrablewebapplicationcontext

 

Org. springframework. Web. Context

(Light blue background)

. Support

Abstractrefreshablewebapplicationcontext

Xmlwebapplicationcontext

 

 

 

 

 

 

Summary:

1)
Put different things under different packages. It seems like nonsense! The upper-layer package-based interface, the lower-layer package-based abstract classes and entity classes. For example, the contex. support package contains the abstract class and implementation class that implement the interfaces under the context package.

2)
To adapt to the Web-level applicationcontext, The webapplicationcontext interface is created, which inherits applicationcontext and adds the web-layer personalization methods such as getservletcontext and attributes. Now I understand the meaning of "extends" between interfaces. It is definitely an "extension" for upper-layer interfaces. The purpose of expansion is to adapt to a more specific environment. Just as the country is large and the situation is complex, the policies of the central government are relatively abstract. Local Policies must meet the requirements of the Central Government policies in light of local characteristics, that is, to achieve the central policy interface, and expand personalized policies according to local special circumstances, that is, the local policy interface, so as to be more operable.

3)
In Org. springframework. web. context. support. the abstractrefreshablewebappplicationcontext class implements both the configrablewebapplicationcontext interface, that is, the Web personalization feature, and inherits Org. springframework. context. support. abstractrefreshableapplicationcontext class. With the help of existing classes, the architecture can be reused. This is like formulating policies that meet local characteristics and can refer to existing policy experiences in other regions. Haha! In actual work, such a design is often used.

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.