(Turn) Spring mind map, so that Spring is no longer difficult to understand (ioc chapter)

         Preface: I plan to start a series of articles on the Spring module, check the existing articles and blogs on the Internet, and find that there are a lot of introductions about Spring, including many articles that explain the profound things in a simple way. In particular, I found that the mind map can briefly explain related concepts and the relationship between them, so I quoted and organized an article introducing SpringIOC to share with you.

This article focuses on the following issues:

  • Spring knowledge details
  • Inversion of Control
  • spring ioc container
  • Core components work together
  • The difference between BeanFactory and ApplicationContext
  • 3 injection methods
  • Principle analysis

1. Spring knowledge details

       Anyone who has written java knows: all objects must be created; or: objects must be created before they are used. After using ioc, you can no longer create objects manually, but get objects directly from the ioc container. It's as if we don't need to consider the destruction and recycling of objects, because the java garbage collection mechanism helps us realize this process; and ioc lets us not need to consider the creation process of objects, and the ioc container helps us realize the process of object creation, injection, etc.

2. Inversion of Control

3. IOC container 

          There are only three core components in the Spring framework: Core, Context and Bean. They build the skeleton architecture of the entire Spring, without them it is impossible to have features such as AOP and Web.

         If it is said that one core is selected from the three cores, it is none other than Bean. It can be said that Spring is Bean-oriented programming, and Bean is the real protagonist in Spring. Why is Spring so popular? You will find that Spring solves a very critical problem, it allows you to use configuration files to manage the relationship between objects, or annotations, that is, its dependency injection mechanism. And this injection relationship is managed in a container called Ioc. The Ioc container is the object wrapped by the Bean. Spring achieves the purpose of managing these objects and doing some additional operations by wrapping objects in Beans.

        How IOCs work:

         SpringIOC initialization:

         How SpringIOC works:

 

 4. Core components work together  

5. Difference between BeanFactory and ApplicationContext

       The core interface in IOC is that Beanfactory provides high-level services of IOC, and ApplicationContext is based on BeanFactory to provide abstract application-oriented services.  

 6. Three injection methods

         In the Spring framework, the Dependency Injection (DI) design pattern is used to define the dependencies between objects. In the case of bean configuration using xml, it is mainly of two types:

  • Setter method injection
  • Constructor injection

        Of course, with annotations, the way to use annotations is more convenient and faster. That is, the autowiring function implements automatic property injection (@autowire). Writing this reminds me of a multiple-choice question I recently read on Niuke.com:

  The following statement about spring's dependency injection is wrong? (C?)

  A. There are usually two types of dependency injection: setup injection and construction injection:
  B. Constructive injection can determine the injection order of dependencies in the constructor, and prioritize the injection of dependencies
  C. When setting injection and construction injection exist at the same time, perform construction injection first, and then perform setting injection
  D. Set value injection means that the IoC container uses the property setter method to inject the dependent instance. This injection method is relatively simple and intuitive

 

7. Principle analysis

         Later, I will introduce the general usage of IOC and the tracking of the source code.

Guess you like

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