开发者社区 问答 正文

ApplicationContext Resource leak: 'ctx' is never closed

ApplicationContext ctx = new ClassPathXmlApplicationContext("beans.xml");

eclipse总是提示这一句

Resource leak: 'ctx' is never closed

但是ApplicationContext ctx里面没有close方法

请问,怎么破

展开
收起
a123456678 2016-03-18 15:42:25 4995 分享 版权
1 条回答
写回答
取消 提交回答
  • ApplicationContext ctx声明为成员变量

    public class UserServiceTest {
         
        private static UserService us;
        private static ApplicationContext ctx;
     
        @BeforeClass
        public static void setUpBeforeClass() throws Exception {
             ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
             us=(UserService) ctx.getBean("userService");
        }
     
        @Test
        public void testSave() {
             
        }
    }
    2019-07-17 19:06:53
    赞同 1 展开评论
问答分类:
问答地址: