The core of Spring!
Manages Beans (objects) that constitute a program using DI (Dependency Injection)
Loads Beans when they are used (Lazy-loading)
- A class that creates and manages Bean objects
- Responsible for
managing Beans, including creating, looking up, and returning Beans - BeanFactory loads Bean definitions immediately, but does not instantiate the Bean itself until it is called
- When
getBean()is called, only then does the Factory instantiate the received Bean using Dependency Injection (DI) and set the Bean's properties →On-demandapproach
- When
- Focuses on the basic IoC functionality of creating Beans and configuring relationships
How Beans are created and loadedBeanFactoryusesLazy-loading- Instances are created and loaded at the point when a method or class receives a Bean loading request
- Therefore, instances are created and loaded at the point when requested by the
.getBean()method
- Therefore, instances are created and loaded at the point when requested by the
Loads all Beans at runtime startup (Pre-loading)
- Similar to BeanFactory, but a more enhanced form of container
- Focuses on overseeing the overall control of Bean creation, relationship configuration, etc., by referencing separate information
How Beans are created and loadedApplicationContextusesPre-loading- All Beans and configuration files are instantiated and loaded when a load request is made by the ApplicationContext
- The reason they are divided into two approaches is because of the relationship between
usage frequencyandresources used- If a Bean is not frequently used, it should be loaded only when actually requested to save consumed resources (Lazy-loading) →
Use BeanFactory - If a Bean is frequently used, it is better to load it all at once (Pre-loading) →
Use ApplicationContext
- If a Bean is not frequently used, it should be loaded only when actually requested to save consumed resources (Lazy-loading) →