Shutdown Spring ApplicationContext

Shutdown Spring ApplicationContextArticle describes the options of, how to Shutdown Spring ApplicationContext in standalone application.

Here goes an optimal approach to get access to spring ApplicationContext, by allowing spring to inject its context into our custom class via implementing ApplicationContextAware interface

That’s it, now we have access to spring application context is achieved.

Note: Web Application doesn’t need to explicitly invoke context.close() or context.registerShutdownHook().

Shutdown Spring ApplicationContext could be achieved using local variable applicationContext as given approaches. Reference of AbstractApplicationContext.

Registering Shutdown Hook

Calling close method


Conclusion

We have seen how to efficiently access Spring ApplicationContext and various options of Shutdown Spring ApplicationContext in standalone application.