Spring ApplicationContext - Resource leak: 'context' is never closed

前端 未结 17 592
伪装坚强ぢ
伪装坚强ぢ 2020-12-04 17:15

In a spring MVC application, I initialize a variable in one of the service classes using the following approach:

ApplicationContext context = 
         new C         


        
17条回答
  •  旧巷少年郎
    2020-12-04 17:56

    The method close has been added to ConfigurableApplicationContext interface, so the best you can do to get access to it is:

    ConfigurableApplicationContext context = new ClassPathXmlApplicationContext(
                    "/app-context.xml");
    
    // Use the context...
    
    context.close();
    

提交回复
热议问题