1. What is an IoC container
1. What is a container
1. Provides an environment for objects to run; 2. Manages the entire life cycle of objects; 3Copy the code
2. What is an IoC container
IoC is the inversion of control that gives the power to create objects to the container, users only need to declare and call -> do not need to manually create objects.DL dependency injection container to manage user declared relations -> do not need to manually set, IoC implementation form 3. Main process: resource awareness positioning, parsing, registration of BeanDefinition management, enhancement of Bean object instantiation, initialization of Bean object dependency management, and injectionCopy the code
3.IoC container and Spring IoC container
2. JavaBeans and Java ServiceLoader(SPI) JNDI in JavaSE can be used as IoC containers JavaBeans are used and defined to meet the concept of control and dependency of an IoC container.SPI assigns the location, access, loading, and creation of a Class to the JVM, also known as an IoC container. EJB in JavaEE is a traditional implementation and Servlet dependency on JNDI open source Apache Avalon has been discontinued /PicoContainer(from which Spring dependency injection was inspired) Google Guice lightweight framework And, of course, the undisputed Spring FrameworkCopy the code
4. What do you think of the Spring IoC container
1. For spring IoC IoC container is a product, in addition to the basic ability of ConfigurableApplicationContext container, spring provides a wide variety of products to adapt to different usage scenario 2. The spring IoC container 3. Spring is intended to be an ecosystem, a whole family of buckets, not a single framework, providing a whole set of solutions for enterprise applications. As a result, the whole set of frameworks becomes heavy, so you need to know which IoC container you are using and which support is provided by default 4. Spring is suitable for enterprise-level business development, which is concise, efficient and easy to use. It is not suitable for middleware/component developmentCopy the code
2. Why use the Spring IoC container
1. Nanny-style framework, easy to use, low cost to learn 2. Powerful expansion ability, providing too many possibilities,beanFactory and BeanPostProcessor mechanism 3. A strong ecosystem that integrates with almost all major frameworks, while emerging frameworks provide support for Spring 4. The vast number of users, you have a problem, someone has always appeared, find a solution faster 5. Other IoC containers have either feature completion or high learning costsCopy the code
3. How to use the Spring IoC container
1. Web container listeners
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
Copy the code
The traditional Web container method is to start the Web container -> start the webListener-> create the IoC container
2. Springboot way
Springapplication. run(thisClass)Copy the code
Springboot start ->applicationClass Main method -> Springboot Listener,initlizer-> Spring Cloud system Ioc parent -> current application child Ioc container -> Start and bind Tomcat