Header Ads

ad

Bean Life Cycle in Spring

Bean Life Cycle


To keep track of all the activities of an object from birth(Object creation) to death(Object destruction) of spring bean class is called Bean Life Cycle...

>> In Servlet Life cycle we were using following life cycle methods:
a) init(-)
b) service(-,-)
c) destroy()

>> In ordinary class we use constructor, finalize() method to place initialization and uninitialization logics.

>> But Spring provides two life cycle methods:

a) init-method

>> It executes after all dependent values are injected.
>> In init() method we place the logics to check whether important properties are injected with correct values or not.
>> Here we also place the initialization logics of those properties that are not configured for injection..

b) destroy-method

>> It executes when IOC container is about to destroy our bean class object.
>> Here we place uninitialization logics of non java resources.


No comments