The objects that form the backbone of your
application and that are managed by the Spring IOC container are called beans.
A bean is an object that is instantiated, assembled and managed by Spring IOC
container.
The beans are created with the configuration
metadata provided in the form of XML. The bean definition contains the
information called configuration metadata which is needed for the container to
know the following items:
How to create a bean
Bean’s life cycle details
Bean’s dependencies
All the
above configuration metadata translates into a set of the following properties
that makeup each bean definition.
Class
– This attribute is mandatory and
specifies which bean class to be used
Scope – This attribute specifies the scope of the
object
Name/ID – This attribute specifies the bean identifier
uniquely. We use either id.name to specify the bean identifier(s).
Constructor–arg – This is used to inject the
dependency using constructor
properties – This is used to inject the
dependencies using setters
Autowiring
mode – This is used to inject the dependencies
Lazy-intialization
mode – A
lazy-initialized bean tells the IOC container to create a bean instance when it
is first requested rather than at start up of the application
Initialization
method – A
callback to be called just after all necessary properties on the bean have set
by the container.
Destruction
method – A
callback to be called when the container containing the bean is destroyed.
<!-- A simple
bean definition -->
<bean
id="..." class="...">
<!--
collaborators and configuration for this bean go here -->
</bean>
<!-- A bean
definition with lazy init set on -->
<bean
id="..." class="..." lazy-init="true">
<!--
collaborators and configuration for this bean go here -->
</bean>
<!-- A bean
definition with initialization method -->
<bean
id="..." class="..." init-method="...">
<!--
collaborators and configuration for this bean go here -->
</bean>
<!-- A bean
definition with destruction method -->
<bean
id="..." class="..." destroy-method="...">
<!--
collaborators and configuration for this bean go here -->
</bean>
<!-- A bean definition with initialization with scope
-->
<bean
id="..." class="..."
scope="...">
<!--
collaborators and configuration for this bean go here -->
</bean>
<!-- A bean definition with inheritance -->
<bean
id="..." class="..."
parent="...">
<!--
collaborators and configuration for this bean go here -->
</bean>
<!-- more
bean definitions go here -->
</beans>
No comments:
Post a Comment