Beans are managed by IOC container, having a life cycle associated with it. These are the possible ways of managing there life cycle:
- Callback API implementation
- XML configuration
- Annotations
There are two distinct spring containers one is bean factory and another is application context. Life cycle phases varies a lil in the containers. More precisely, only one additional phase is added in case of application context. Let's see what these phases are:
- Instantiate: in this phase container finds the bean's definition and default constructor called.
- Autowiring executes
- Dependency check performed
- setters method of bean called
- setBeanFactory () / setApplicationContext () / method called
- afterPropertiesSet() / init-method /@PostConstruct method called
- Application running, beans ready to work
- destroy()/ destroy-method / @PreDestroy method called
An existing bean can be removed from the container in two ways:
1. DisposableBean: If bean implements the DisposableBean interface then destroy() method is called.
2. Call-custom destroy: if custom-destroy method is specified then it is called.
No comments:
Post a Comment