spring architecture learning one

20180507 check

 

There are three core components of the spring framework: Core, Context, and Beans. If Bean is compared to an actor in a show, then Context is the stage background of the show, and Core should be the props of the show. Bean wraps Object, and Object must have data. How to provide a living environment for these data is the problem to be solved by Context. For Context, it is to discover the relationship between each Bean, establish this relationship for them and require Maintain this relationship. So Context is a collection of Bean relationships, which is also called the Ioc container. Once the Ioc container is established, Spring can work for you. So what's the use of Core components? In fact, Core is a series of tools needed to discover, establish and maintain the relationship between each Bean. From this point of view, the Core component called Util can make you understand better.

Bean:

The starting spring is Bean Oriented Programming (BOP, Bean Oriented Programming), and Bean is the real protagonist in Spring.

The dependencies between objects are managed by configuration files, which is his dependency injection mechanism. And this injection relationship is managed in a container called Ioc, which is the object wrapped by Bean. Spring achieves the purpose of managing these objects and a series of additional operations by wrapping objects in beans.

A typical factory pattern when SpringBean is created, its top-level interface is BeanFactory.

BeanFactory has three subclasses: ListableBeanFactory, HierarchicalBeanFactory and Autowire Capable Bean Factory. The final default implementation class is DefaultListableBeanFactory, which implements all interfaces. These interfaces are mainly to distinguish the restrictions on the data access of objects during the transfer and transformation of objects in the operation process within Spring. For example, the ListableBeanFactory interface indicates that these beans are listable, while the HierarchicalBeanFactory indicates that these beans are inherited, that is, each bean may have a parent bean. The AutowireCapableBeanFactory interface defines the autowiring rules for beans. These four interfaces jointly define the collection of beans, the relationship between beans, and the behavior of beans.

Context:

ApplicationContext is the top-level parent class of Context. In addition to identifying the basic information of an application environment, it also inherits five interfaces, which mainly extend the functions of Context. ApplicationContext inherits BeanFactory, which also shows that the main object running in the Spring container is Bean, and ApplicationContext inherits the ResourceLoader interface, so that ApplicationContext can access any external resources. ConfigurableApplicationContext indicates that the Context is modifiable, that is, the user can dynamically add or modify the existing configuration information during the construction of the Context.

In general, ApplicationContext must complete the following things:

  • Identify an application environment
  • Use BeanFactory to create Bean objects
  • save object relation table
  • Capable of capturing various events

As Spring's Ioc container, Context basically integrates most of Spring's functions, or is the basis for most functions.

Core:

As the core component of Spring, the Core component contains many key classes, one of which is to define the access method of resources. The Resource interface encapsulates various possible resource types.

Context delegates the loading, parsing and description of resources to the ResourcePatternResolver class. He is equivalent to a connector. He integrates the loading, parsing and definition of resources for other components to use.

Ioc container:

The Ioc container is actually a Bean relationship network constructed by the Context component combined with the other two components.

The process of building the entire Ioc container mainly includes the following steps:

  • Build the BeanFactory to produce the required "actors"
  • Register for events that may be of interest
  • Create Bean instance object
  • Trigger the monitored event

Think of an Ioc container as a box that has several molds for balls that can be used to make many different kinds of balls, and a machine that makes these molds, and this machine can produce molds. Then their corresponding relationship is that the BeanFactory is the machine that makes the ball mold, the ball mold is the Bean, and the ball created by the ball mold is the instance of the Bean. So where are the expansion points mentioned above? BeanFactoryPostProcessor corresponds to when the ball mold is created, you will have the opportunity to make appropriate corrections to it, that is, he can modify the ball mold for you. While InitializingBean and DisposableBean are at the beginning and end of ball modeling, you can do some prep and finishing work. The BeanPostProcessor will allow you to make appropriate corrections to the ball you model. Finally, there is a FactoryBean, which is a magical ball mold. This ball model is not pre-shaped, but it is up to you to determine its shape. Since you can determine the shape of the ball model, of course, the ball he created must be the one you want, so in this box Here you can find all the balls you want.

acting:

The purpose of the proxy is that we can turn to execute the invoke method of the InvocationHandler class when calling the target method, so how to make a fuss on the InvocationHandler is the key to Spring's implementation of Aop.

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325609949&siteId=291194637