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

前端 未结 17 587
伪装坚强ぢ
伪装坚强ぢ 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 18:01

    If you are using the ClassPathXmlApplicationContext then you can use

    ((ClassPathXmlApplicationContext) context).close();
    

    to close the resource leak problem.

    If you are using the AbstractApplicationContext then you can cast this with close method.

    ((AbstractApplicationContext) context).close();
    

    It depends on the type of context using in the application.

提交回复
热议问题