Resource leak: 'context' is never closed

spring实例化时

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

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

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


你可能感兴趣的:(错误记录)