This is the third day of my participation in Gwen Challenge

Spring’s IoC container is an IoC Service Provider, but that’s only part of the reason it’s named IoC. What we can’t ignore is the container. Spring’s IoC container is a lightweight container that provides IoC support, in addition to basic IoC support, as a lightweight container that provides support beyond IoC. For example, on top of Spring’s IoC container, Spring also provides corresponding AOP framework support, enterprise service integration, and other services. There is an intersection between the Spring IoC container and the services provided by the IoC Service Provider, as shown below.

Spring provides two container types: BeanFactory and ApplicationContext

BeanFactory: Basic IoC container that provides full IoC service support. If no specific initialization policy is specified, lazy-load is used by default. Initialization and dependency injection are performed only when a client needs to access a managed object in the container. As a result, containers are relatively quick to start up and require limited resources. Suitable for scenarios with less stringent functional requirements.

ApplicationContext: ApplicationContext is built on top of BeanFactory and is a relatively high-level container. In addition to having all the support of a BeanFactory, ApplicationContext provides other advanced features. For example, event publishing, international information support, etc. Objects managed by ApplicationContext are all initialized and bound by default after the container of that type is started. Therefore, the ApplicationContext requires more system resources, and since all initialization is done at startup, the startup time is longer than that of the BeanFactory.

The following figure gives you a clearer idea of the relationship between BeanFactory and ApplicationContext.

Before we had the BeanFactory, we usually instantiated the corresponding object ourselves and called it directly in the main method of the entry class of our application, as follows:

FXNewsProvider newsProvider = new FXNewsProvider();
newsProvider.getAndPersistNews();
Copy the code

Once we have The BeanFactory, we usually just hand over the “production drawings” to the BeanFactory and have the BeanFactory produce an FXNewsProvider for us, with the following code:

ApplicationContext container = new ClassPathXmlApplicationContext (" configuration file path "); FXNewsProvider newsProvider = (FXNewsProvider)container.getBean("djNewsProvider"); newsProvider.getAndPersistNews();Copy the code