Reputation: 42957
I am studying Spring Framework and now I am studying about the init and the destroy beans callbacl method.
I am following this tutorial: http://www.tutorialspoint.com/spring/spring_bean_life_cycle.htm
I have some doubts about this tutorial:
1) Why in the MainApp class he declare the context as AbstractApplicationContext but create it using the implementation ClassPathXmlApplicationContext ? Is it because I can override the init() and destroy() methods ? or for what else?
2) What exactly do the context.registerShutdownHook(); method?
Upvotes: 0
Views: 348
Reputation: 242686
AbstractApplicationContext
is where registerShutdownHook()
is declared. So, you need to use this class (or any of its subclasses) in variable declaration in order to call registerShutdownHook()
on your application context.
registerShutdownHook()
registers a JVM shutdown hook that would close the application context (destroying all beans) upon JVM shutdown
Upvotes: 2