Close spring application context

Once your application finishes you should close spring application context . Below is example:

Downcast ApplicationContext to ConfigurableApplicationContext which has close() method:

((ConfigurableApplicationContext)appCtx).close();

 

OR:

You can also cast to AbstractApplicationContext and register shutdown with JVM:

((AbstractApplicationContext)applicationContext).registerShutdownHook();

 

OR:

cast to AbstractApplicationContext and call close() method:

((AbstractApplicationContext)applicationContext).close();

Leave a Reply

Your email address will not be published. Required fields are marked *

I am not Robot *