zoukankan      html  css  js  c++  java
  • Resource leak: 'context' is never closed

    spring实例化时

    [java] view plain copy
     
    1. public void test2() {  
    2.     ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");  
    3.     //配置文件中的id属性  
    4.     IHelloService service = (IHelloService) context.getBean("helloService");  
    5.     service.sayHello();  
    6.       
    7. }  


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

    [java] view plain copy
     
      1. public void test2() {  
      2.     ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");  
      3.     //配置文件中的id属性  
      4.     IHelloService service = (IHelloService) context.getBean("helloService");  
      5.     service.sayHello();  
      6.     context.close();  
      7. }  
  • 相关阅读:
    asp.net pager
    asp.net 2.0
    mul page
    基于 Ajax 的持久对象映射(reship)
    asp.net run
    reship HttpProc
    some questions
    rss feed
    javascript function
    ioc
  • 原文地址:https://www.cnblogs.com/exmyth/p/5764156.html
Copyright © 2011-2022 走看看