ConfigurableApplicationContext vs ApplicationContext

后端 未结 2 1854
后悔当初
后悔当初 2020-12-18 00:23

I have been learning spring framework for some time.But whenever I look for initialization and destruction callbacks, every example uses ConfigurableApplicationContext inste

2条回答
  •  清歌不尽
    2020-12-18 01:04

    Because all common implementation of ApplicationContext are in fact ConfigurableApplicationContext. Extract from javadoc for ConfigurableApplicationContext :

    SPI interface to be implemented by most if not all application contexts.

    and

    Configuration and lifecycle methods are encapsulated here to avoid making them obvious to ApplicationContext client code. The present methods should only be used by startup and shutdown code

    That means that when you use an application context, i.e. get beans from it you only use it as an ApplicationContext but when you manage its life cycle (initialization and destruction) you use methods from ConfigurableApplicationContext

提交回复
热议问题