what is the difference between AbstractApplicationContext
and ApplicationContext
?
can we call
context.registerShutdownHook()
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
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.
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