Spring bean

A spring bean represents an object that is created, configured and managed by spring container. A spring bean is created by configuration metadata passed to the spring container which tells the container about bean creation, bean lifecycle and bean dependencies.

Spring bean properties:

Bean Properties Description
1. class It is mandatory and specify the bean class which is used to create the bean.
2. name It specifies the bean unique identifier.
3. scope It specifies the scope of the objects created from a particular bean definition.
4. constructor-arg It is used to inject the dependencies.
5. properties It is used to inject the dependencies.
6. autowiring mode It is used to inject the dependencies.
7. lazy-initialization mode It tells the IoC container to create a bean instance when it is first requested, rather than at startup.
8. initialization method It is a callback method to be called just after all necessary properties on the bean have been set by the container.
9. destruction method It is a callback to be called when the container containing the bean is destroyed.


Syntax using XML based configuration file:

       //bean configuration