Spring Summary-IOC and Bean summary, spring summary iocbean
1. The overall structure of Spring in the official Spring document.
Ii. Overall structure of Spring as I understand it.
Iii. Summary of the core part of Spring
1. As shown in the figure above, Beans, Context, and Core components are the Core components of Spring. They constitute the skeleton of Spring.
2. From the very beginning, Spring eventually operates on beans, so Bean is the core of the entire Spring core.
3. Unlike the idea of normal programming, Spring switches the dependency between objects to the configuration file for management, that is, its dependency injection mechanism. The injection relationship is managed in an IOC container.
What is included in the IOC container? Actually, it is the objects contained by beans. The IOC container can be considered as a set of beans.
4. this design strategy is similar to the OOP design concept implemented by Java. It constructs a data structure, designs its survival environment based on the data structure, and assigns it a lifecycle, make him under certain rules
You can interact with other individuals in the process of continuous motion.
5. how to work collaboratively between Core components: for example, if Bean is an actor of a drama, Context is the stage, and Core is the prop, the three of them are the most basic elements of drama.
We know that Bean wraps an Object, and the Object contains data, and providing a living environment for the data is the problem to be solved by Context. For Context, it needs to find every Bean, and Bean and
Establish and maintain the relationship between beans. Therefore, Context is the set of Bean relations, which is also called the IOC container. Once this container is created, Spring can work. So Core is
What is used? A series of tools required to discover, establish, and maintain the relationship between beans. It provides support for Bean components and Context components.
Iv. Bean components
1. the Bean component is located under the org. springframework. beans package of Spring.
All classes in this package mainly solve three things: Bean definition, Bean creation, and Bean parsing. For users, we only need to pay attention to Bean creation and then OK. The other two are completed by Spring.
2. Spring Bean is created in a typical factory mode. Its top-level interface is BeanFactory.
3. BeanDefinition describes Bean definitions, which describe all the information of <Bean> nodes and Their subnodes in the Spring Config file.
After Spring successfully parses a <bean> node you defined, it will be converted into a BeanDefinition object in Spring. All subsequent operations will be completed by this object.
4. Bean parsing mainly refers to parsing the Spring configuration file. The top-level interfaces are BeanDefinitionReader and BeanDefinitionDocumentReader.
5. Context components
1. The Context component is located in the org. springframework. context package of Spring. It serves to provide a runtime environment for Bean and maintain the relationship between beans.
2. BeanFactory serves as the top-level interface of Context.
ApplicationContext is a common interface of the Context component. It not only identifies the basic information of an application environment, but also inherits six interfaces, which extend the Context function.
From this we can see that the ApplicationContext interface inherits the BeanFactory interface, and we can also see that the main body of Spring running is Bean. In addition, it indirectly inherits the ResourceLoader interface,
You can also access external resources.
Then let's look at its two sub-interfaces:
(1). ConfigurableApplicationContext indicates that the Context can be modified. That is to say, you can add or modify existing configurations when building the Context.
(2). WebApplicationContext is the Context prepared for the Web environment. It can access ServletContext.
For ApplicationContext, you must do the following:
(1) Identify an application environment
(2) Using BeanFactory to create Bean objects
(3) Save the object relationship table
(4) ability to capture various events
As the IOC container of Spring, Context basically integrates most of Spring functions, or is the basis of most functions.
Vi. Core Components
1. As the Core component of Spring, the Core component contains many key classes. An important component is to define the resource access method. Abstract all resources into an interface Resource.
Resource class structure:
The Resource class encapsulates various possible Resource types, inherits the InputStreamSource interface, and shields users from different Resource types. All resources can be obtained through getInputStream.
2. the relationship between Context and Resource: Context refers to entrusting Resource loading, parsing, and description to the ResourcePatternResolver class. It integrates Resource loading, parsing, and Resource definition for convenience.
Use other components.
7. How does the IOC container work?
1. The IOC container is actually combining the other two components to build a bean network.
2. How to Create a BeanFactory
3. How to Create Bean instances and build the relationship between beans
4. How to extend Bean
8. The above content introduces the three core components of Spring from a macro perspective. Most of the content is for reference by others. Details of specific knowledge are listed below.
9. What I want to talk about at the end is that I think that if I want to learn Spring well, I must have a deep understanding of its thoughts and learn from it as a driver. I have some rules to get twice the result with half the effort.
References: https://www.ibm.com/developerworks/cn/java/j-lo-spring-principle/