遇见的问题:
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();
}