What is the difference between BeanPostProcessor and init/destroy method in Spring?

前端 未结 6 1340
不思量自难忘°
不思量自难忘° 2021-01-29 20:34

What is the difference between implementing the BeanPostProcessor interface and either using the init/destroy method attributes in the XML

6条回答
  •  情深已故
    2021-01-29 20:44

    And one more main diff is InitializingBean,DisposableBean related afterPropertiesSet() & destory() methods did not accept any paratmeters and return type also void, so we did not implement any custom logic. But coming to BeanPostProcess methods postProcessBeforeInitialization(Object bean,String beanName) and postProcessAfterInitilization(Object bean,String beanName) are accept those two paramaters and return type also Object so we are able to write initilzation logics as well as any custom login based on the passing bean...

    These both callback method feautes are including the bean life cycle and the following are the life cycle as follows

    1) BeanPostProcessor.postProcessBeforeInitilazation()

    2) @postConstruct or InitializingBean.afterPropertiesSet() or initialization method which is
    defining in xml /* here also it's following the same oredr if three ways are availiable **/

    3) BeanPostProcessor.postProcessAfterInitialization()

    4) @preDestroy or DisposibleBean.destroy() or destroy method which is defining in xml /* here also it's following the same oredr if three ways are availiable **/

提交回复
热议问题