AbstractApplicationContext vs ApplicationContext

后端 未结 3 1626
悲哀的现实
悲哀的现实 2021-02-19 15:06

what is the difference between AbstractApplicationContext and ApplicationContext ? can we call

context.registerShutdownHook()  


        
相关标签:
3条回答
  • 2021-02-19 15:51

    registerShutdownHook() gracefully shutdowns bean and preform finalization like calling the destroy methods. This is the method declared in the interface ConfigurableApplicationContext which is implemented by AbstractApplicationContext,and it is not implemented by ApplicationContext.So the invokation of registerShutdownHook() only possible from the AbstractApplicationContext's object

    0 讨论(0)
  • 2021-02-19 16:01

    registerShutdownHook() is not part of ApplicationContext. So, we can not use Application context.

    This method can be invoked using references using with either ConfigurableApplicationContext or AbstractApplicationContext.

    As methods can be called either from interface or class having the implementation. Because, we actually create object for ClassPathXmlApplicationContext using the reference of AbstractApplicationContext.

    Difference: ConfigurableApplicationContext is an interface where the methods are implemented in AbstractApplicationContext class.

    0 讨论(0)
  • 2021-02-19 16:08

    Same as the diff between abstract class (AbstractApplicationContext ) and an interface (ApplicationContext).

    Can we call context.registerShutdownHook() using ApplicationContext?

    No, because registerShutdownHook() is part of ConfigurableApplicationContext interface which is not extended by ApplicationContext

    0 讨论(0)
提交回复
热议问题