There are several spring articles written in front of you, and the feeling and the theme are not very relevant. Re-organize your ideas and write the article from a more understandable perspective.
Spring's skeleton, the skeleton of spring, is also the core package of spring. It contains three content 1.context:spring on-line text-------
Director2.core:spring's core package, which mainly includes the tools that spring uses-------
PropsThe bean instance of 3.beans:spring-------
actor
The Director is responsible for arranging the performance, the actor is responsible according to the director's instruction to perform, the performance process needs to use the props.
I think we can understand the general package relationship after reading these pictures.
Spring Package Structure
Everyone sees the corresponding package content. The core package focuses on helper classes, manipulation tools, and beans packages that focus more on the description of the Bean instance. Context more focused on global control, functional derivation. Let's continue with a basic summary of the relationship between the context and factory for the class:
The relationship between core classes Let's take a look at the Beanfactory class under the Bean package, as well as the abstract class.
You can see that in the process of implementing generalization of an interface, each interface inherits the parent interface while inheriting some methods of the parent interface. This makes it clear that the interface becomes subtle. Beanfactory "All Beanfactory's parent class"
You can see that some basic methods are defined in Beanfactory, including getting bean instances by name, and so on. Hierarchicalbeanfactory "Hierarchical Beanfactory"
You can see that this interface is hierarchical and gets the parent container of beanfactory lisablebeanfactory list beanfactory
You can see the ability to set a list for beanfactory and plan how to remove the appropriate method from the list. Summary: From the above class naming and interface planning can be seen, through the continuous inheritance of the interface, Beanfactory is constantly enriched abstract up. After the layers are broken down, no class has a single function, and it becomes more convenient to extend the attribute. For the source code, the best way is also based on the name, the most convenient. Context "Upper Downline text"
You can see that the initialization of the context differs from the beanfactory, which can be focused on abstract types, which are implemented in concrete ways. Most of the methods used in the template method design pattern, the parent class calls the abstract method, the abstract method is implemented in the subclass, the object independence. Mainly divided into three kinds of context:xml,annotation,groovy for three forms.
Registry "Instance or bean description Registrar"
In the container that initializes the completed bean registration, for a singleton, a partial, instance of a sample of the deposit. For the Beandefinition section, cache the bean description.
Strategy "Initialize policy"
The two types of initialization strategies are simple, one is cgilib, and the pattern used here is the policy mode. Initialization of the context
/** * Create classpathxmlapplicaitoncontext under Parent, * Read all bean definitions from XML. * @param configlocations profile path such as C:\simpleContext.xml * @param refresh requires automatic refresh context,refresh--> reload * Load all bean definitions, Create all the Singleton. * Refresh is true when manually refreshing according to context * @param parent The parent context * @throws Beansexception If context creation failed * @see #refresh () */public classpathxmlapplicationcontext (string[] configlocations, boolean refresh, ApplicationContext Parent) throws Beansexception {//Initialize Xmlapplicationcontextsuper (parent);//Convert configuration file path Setconfiglocations ( Configlocations); if (refresh) {//re-refreshes the original context, the focus of this article is refresh ();}}
let's look at the following Abstractapplicationcontext.refresh () method
Loading or refreshing a persistent configuration can be a summary of an XML file, a properties file, or a relational database. As a startup method, if the initialization failure will destroy the already created singleton, avoid repeatedly loading the configuration file. In other words, after executing this method, either load the singleton or not load public void refresh () throws Beansexception, IllegalStateException {synchronized ( This.startupshutdownmonitor) {//Initialize configuration ready to refresh, verify some of the required parameters in the environment variable Preparerefresh ();//Tell the inheriting class to destroy internal factory create a new instance of factory// Initializes the bean instance configurablelistablebeanfactory beanfactory = Obtainfreshbeanfactory ();//initializes the Beanfactroy basic information, including classloader,environment, ignored annotations, etc. preparebeanfactory (beanfactory); try {//beanfactory internal postprocess, Can be understood as a supplementary beanfactory.postprocessbeanfactory (beanfactory) of postprocess in the context; Execute Beanfactorypostprocessor (during beanfactory initialization, before the bean is initialized, modify the beanfactory parameter),//Beandefinitionregistrypostprocessor In fact, also inherited from beanfactorypostprocessor,//more to Beandefinitionregistry support Invokebeanfactorypostprocessors (beanFactory); Execute postprocess, what is the beanpostprocessor, is to modify the bean content during the bean loading process,//using two of the points and methods before, After respectively corresponds to pre-initialization and after initialization registerbeanpostprocessors (beanfactory);//Initialize Messagesource, mainly used for i18n localized content initmessagesOurce ();//Initialize event broadcast Applicationeventmulticaster, use observer mode to capture applicationevent time of registration Initapplicationeventmulticaster ();//Initialize the special Bean Method Onrefresh ();//Register All Applicationeventlistener in Applicationeventmulticaster registerlisteners (); /Initialize all Bean,singleton instances that are not lazy-init finishbeanfactoryinitialization (beanfactory);// Initialize the lifecycle bean and start it (for example, quartz timer, etc.), and if you turn on JMX, register the ApplicationContext with Finishrefresh ();} catch (Beansexception ex) {//Destroy has created a singleton resources.destroybeans ();//Convert the state of the context to an invalid, flag initialization failure Flag.cancelrefresh (ex);// Propagate exception to caller throw ex;}}}We start the above initialization from the time series diagram (façade mode facade)
Spring Framework 4 Source Reading