title: Spring ApplicationContext - Resource leak: 'context' is never closed
body: <p>In a spring MVC application, I initialize a variable in one of the service classes using the following approach:</p>
  
  <pre><code>ApplicationContext context = 
           new ClassPathXmlApplicationContext("META-INF/userLibrary.xml");
  service = context.getBean(UserLibrary.class);
  </code></pre>
  
  <p>The UserLibrary is a 3rd party utility which I am using in my application. The above code generates a warning for the 'context' variable. The warning is shown below:</p>
  
  <pre><code>Resource leak: 'context' is never closed
  </code></pre>
  
  <p>I don't understand the warning. As the application is a Spring MVC application, I can't really close/destroy the context as I refer to the service while the application is running. What exactly is the warning trying to tell me?</p>