如何closures一个Spring ApplicationContext?
我的应用程序完成后,我想closuresspring的上下文。 
 相关的代码有一个ApplicationContext引用,但是我找不到一个close方法。 
 将您的ApplicationContext到定义close()方法的ConfigurableApplicationContext中: 
 ((ConfigurableApplicationContext)appCtx).close(); 
您需要使用JVM注册一个closures钩子,如下所示:
 ((AbstractApplicationContext)appCtx).registerShutdownHook(); 
有关更多信息,请参阅: Spring Manual:3.6.1.6在非Web应用程序中正常closuresSpring IoC容器
如果你初始化下面的一个上下文
 ApplicationContext context = new ClassPathXmlApplicationContext(beansXML); 
像这些干净的上下文
 ((ClassPathXmlApplicationContext) context).close(); 
如果Java SE 7和更高版本不closures,请使用try-with-resources确保在语句结束时closures每个资源。
 try(final AbstractApplicationContext applicationContext = new ClassPathXmlApplicationContext(new String[]{"classpath*:META-INF/spring/*.xml" })) { //write your code } 
 closuresApplicationContext对象的步骤 
-  types将ApplicationContext对象转换为ConfigurableApplicationContext对象。
- 然后调用closures的对象。
例:
  ApplicationContext context = new ClassPathXmlApplicationContext("mybeans.xml"); ((ConfigurableApplicationContext)context ).close();