Spring Bean Factory
Table of Contents
Spring Bean Factory
- The root interface for accessing a Spring bean container.
Spring bean factory
is responsible for managing the life cycle of beans created through spring containers.- Depending on the bean definition, the factory will return either an independent instance of a contained object (the Prototype design pattern), or a single shared instance (a superior alternative to the Singleton design pattern, in which the instance is a singleton in the scope of the factory). Which type of instance will be returned depends on the bean factory configuration: the API is the same.
- The point of this approach is that the
BeanFactory
is a central registry of application components, and centralizes configuration of application components (no more do individual objects need to read properties files, for example). - Note that it is generally better to rely on Dependency Injection (“push” configuration) to configure application objects through setters or constructors, rather than use any form of “pull” configuration like a BeanFactory lookup. Spring’s Dependency Injection functionality is implemented using this BeanFactory interface and its subinterfaces.