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

前端 未结 17 613
伪装坚强ぢ
伪装坚强ぢ 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条回答
  •  猫巷女王i
    2020-12-04 18:02

    try this. you need to apply cast to close applicationcontext.

       ClassPathXmlApplicationContext ctx = null;
          try {
             ctx = new ClassPathXmlApplicationContext(...);
                [...]
                 } finally {
                  if (ctx != null)
                      ((AbstractApplicationContext) ctx).close();       
          }
    

提交回复
热议问题