BEAN CONFIGURATION & DEPENDENCY MANAGEMENT :
To configure the beans and their dependency <bean> element is used. This element supports multiple attributes, most commonly used among them are as follows:1. id: is used to assign a unique identifier to the bean.
2. class: used to specify the class name of the bean.
3. factory-method: is used to specify the method which is to be used by the IOC Container for creating the requested bean.
4. factory-bean: to specify the bean which is to is used by the IOC Container for creating the
requested bean.
5. scope: to specify the scope of the bean; A bean can have either of the following scope:
a. Singleton: It is the default scope for the beans, singleton beans are created Only once by the container when they are requested for the very first time. They are shared by the multiple users.
b. Prototype: Prototype beans are created each time they are requested from the container. They are used when different users need to represent different states (i.e.value of the data members).
Note: All of these attributes of the bean are optional
UNDERSTANDING THE OBJECT CREATION BY THE IOC CONTAINER:
An IOC Container can create the beans in two ways1. Directly by using the constructors of the bean class. Read Here : Creating bean by Constructor
2. Indirectly with the help of some factory method. – In case of indirect object creation there can be following scenarios
a. Same class static factory method. Read Here : Creating bean by same class static factory method
b. Different class static factory method. Read Here : Creating bean by different class static factory method
c. Different class Non-Static factory method.Read Here : Creating bean by different class non-static factory method
Read Here : Detailed Example for bean creation and management
Comments
Post a Comment