SpringMvc学习

遇见的问题:

1.Resource leak: 'context' is never closed

spring实例化时

public void test2() {
  ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
  //配置文件中的id属性
  HelloService service = (HelloService) ctx.getBean("helloService");
  service.sayHello();
}

可以将前面用子类来写,并关闭

public void test2() {
  ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
  //配置文件中的id属性
  HelloService service = (HelloService) ctx.getBean("helloService");
  service.sayHello();
  ctx.close();
}

posted @ 2018-05-30 15:50  zKai~  阅读(74)  评论(0编辑  收藏  举报