Overview
Spring is an open source framework to address the complexity of enterprise application development, the books on spring in the bookstore voluminous, online related articles, many of which are well written, introductory examples, problematic solutions, environmental settings, source code analysis, There are spring's integration with other open source systems. This article through the life vernacular, does not rigidly adhere to the spring source code and the specialized terminology fetter, does not rigidly adhere to the concrete realization detail, the analogy introduces the spring container macroscopic design idea. Spring Container Narration
The spring container provides the basic functionality of the spring framework and is the implementation of the factory pattern. In other words, spring is the Bean's factory that manages the life cycle of the bean. So how to design it. The spring source code, while not too voluminous, makes people dizzy, as the following illustration shows, we let the spring container go down the altar, and since it is interface-oriented programming, it is probably clearer to use interfaces to describe the framework without having to adhere to the specific implementation.
Any design is the case, there are raw materials, there are imports, processing, there are exports. Now that spring is the bean's container and the Bean's factory, the production bean process is:
1 raw Material: Bean's configuration file
2) Feed: Read the XML text file through Resourceloader
3) Primary processing: Through the Beandefinitionreader raw materials into semi-finished beandefinition
4 Finishing: Bean's production workshop beanfactory the semi-finished beandefinition into bean
5) Warehousing: finished product library Singletonregistry Save the finished bean, and the Bean's label (Beanid), hehe. You know, this is map work.
The IOC is the SPRNG core. The essential.
The spring container uses control reversal (IOC) mode to separate the application's configuration and dependency specifications from the actual application code, and the control reversal (IOC) pattern is based on the fundamentals of Java reflection.
The usual software design certainly takes the IOC as the core of the container, and other peripheral functions such as the bean's scope are based on the IOC, and spring design only puts it as a tool class Beanutil, which is the genius of spring. Although IOC is the foundation of spring's creation bean, creating a bean needs to determine whether a static factory is created, whether there are constructor methods with parameters, and these parameters may be instances of other objects, creating the initialization method of the bean, and so on, which are not just what the Bean's IOC can cover, And it may take several iterations to invoke the IOC program during the creation of a bean.
To sum up, IOC, though the rationale for spring's Creation bean, is only an important part of it, not the core of the spring container, but the less-than-necessary tool for spring to create beans. The IOC is the key, not the core, of the spring container. Interface Grading Design
The hierarchical design of the interface is for different customers to give different levels of products. Different levels of interface concerns are also different, like the product is divided into several levels, such as advanced products, intermediate products, primary products corresponding to different customer base, or as the bank's customer channels have bank cards, counters, net silver, mobile phone terminals, ATM machines and so on. The same interface is also divided into internal and external interfaces, just as some interfaces may never be known to external users, only internal use, like the internal products between multiple workshops within the factory.
Org.springframework.beans.factory. Beanfactory is the top interface of spring, with only the Getbean series, Containsbean,isprototype, The basic method of Issingleton,gettype and other finished beans.
Org.springframework.beans.factory. Listablebeanfactory is a factory management method such as Containsbeandefinition, Getbeandefinitioncount,getbeandefinitionnames,getbeannamesfortype series, Getbeansoftype series, The listablebeanfactory is aimed at beandefinition semi-finished products.
The ApplicationContext interface, in addition to the integrated Listablebeanfactory interface, also inherits the Resourcepatternresolver,hierarchicalbeanfactory, Applicationeventpublisher,messagesource functions, such as in resource processing (international processing), event delivery, and context implementation between application tiers. The same is the external interface, spring more recommend the use of ApplicationContext reason is here, applicationcontext more like a VIP customer products.
Interface Extended Design
Spring design is an open design idea that is worthy of our architectural design staff to learn, as shown in the following figure:
Com.springframework.beans.factory (Light yellow background) |
| Beanfactory | Listablebeanfactory | Configrablelistablebeanfactory | Defaultlistablebeanfactory |
|
Com.springframework.context (Brownish red background) |
ApplicationContext Configrableapplicationcontext |
|
Org.springframework.context (yellow background) |
. Support |
Abstractapplicat Ioncontext Abstractrefreshableapplicationcontext Abstractxmlapplicationcontext classpathxmlapplicationcontext |
Org.springframework.web.context (Green background) |
Webapplicationcontext Configrablewebapplicationcontext |
|
Org.springframework.web.context (Light blue background) |
. Support |
Abstractrefreshablewebapplicationcontext Xmlwebapplicationcontext |
Summarized as follows:
1 different packages put different things underneath, it seems to be nonsense ah. The upper layer is put on the interface, and the abstract class and entity class are implemented by the lower package. The abstract class and implementation class of the interface below the context package, such as the Contex.support package, are placed below.
2 to accommodate the web-level applicationcontext, a Webapplicationcontext interface has been created, which inherits ApplicationContext, Also adds personalization methods such as Getservletcontext and attributes to the Web layer. Now finally understand the meaning of the "extends" between interfaces, is definitely the "extension" of the upper interface, the purpose of the extension is to adapt to a more specific environment. Just as the country is big, the situation is complex, the central policy is relatively abstract, and local policy must be combined with local characteristics, not only to meet the central policy requirements, that is, the interface to achieve central policy, but also according to local special circumstances, the expansion of personalized policy, that is, local policy interface, thus more operable.
3) The Org.springframework.web.context.support.AbstractRefreshableWebAppplicationContext class is both implemented in Configrablewebapplicationcontext connection , that is to realize the personalized characteristics of the web, but also inherited the Org.springframework.context.support.AbstractRefreshableApplicationContext class. The use of existing classes enables the reuse of the architecture, as is the formulation of policies that cater to local characteristics and can take into account the policy experience available in other regions. Oh. This design is often used in practical work.