In this tutorial we are going to see the overview of Spring Bean.
A bean is an objects that are managed by the Spring IoC container.A Spring IoC container manages one or more beans. These beans are created with the configuration metadata that you supply to the container, for example, in the form of XML <bean/> definitions.
Within the container itself, these bean definitions are represented as BeanDefinition objects, which contain (among other information) the following metadata:
1. A package-qualified class name: typically the actual implementation class of the bean being defined.
2. Bean behavioral configuration elements, which state how the bean should behave in the container (scope, lifecycle callbacks, and so forth).
References to other beans that are needed for the bean to do its work; these references are also called collaborators or dependencies.
3. Other configuration settings to set in the newly created object, for example, the number of connections to use in a bean that manages a connection pool, or the size limit of the pool.
This metadata translates to a set of properties that make up each bean definition.
In addition to bean definitions that contain information on how to create a specific bean, the ApplicationContext implementations also permit the registration of existing objects that are created outside the container, by users. This is done by accessing the ApplicationContext's BeanFactory via the method getBeanFactory() which returns the BeanFactory implementation DefaultListableBeanFactory. DefaultListableBeanFactory supports this registration through the methods registerSingleton(..) and registerBeanDefinition(..). However, typical applications work solely with beans defined through metadata bean definitions.
A bean is an objects that are managed by the Spring IoC container.A Spring IoC container manages one or more beans. These beans are created with the configuration metadata that you supply to the container, for example, in the form of XML <bean/> definitions.
Within the container itself, these bean definitions are represented as BeanDefinition objects, which contain (among other information) the following metadata:
1. A package-qualified class name: typically the actual implementation class of the bean being defined.
2. Bean behavioral configuration elements, which state how the bean should behave in the container (scope, lifecycle callbacks, and so forth).
References to other beans that are needed for the bean to do its work; these references are also called collaborators or dependencies.
3. Other configuration settings to set in the newly created object, for example, the number of connections to use in a bean that manages a connection pool, or the size limit of the pool.
This metadata translates to a set of properties that make up each bean definition.
Property
|
Definition
|
class | This attribute specifies the bean class to be used to create bean |
name | This attribute is specifies bean identifier uniquely. In XML based configuration id/name attribute specify the bean identifier |
scope | This attribute specifies the scope of the object created from a particular bean definition. |
constructor argument | This attribute used to inject dependencies using constructors |
properties | This attribute used to inject dependencies using setter methods |
autowiring mode | This attribute used to inject dependencies automatically without using constructor or properties |
lazy-initialization mode | Lazy-initialization bean tells the IoC container to create bean instance when its first requested rather than startup |
initialization method | The callback to be called just after all necessary properties on the bean have been set by the container |
destruction method | A callback to be used when the container containing the bean is destroyed. |
0 comments:
Post a Comment