from: http://stackoverflow.com/questions/14184059/spring-applicationcontext-resource-leak-context-is-never-closed
Since the app context is a ResourceLoader (i.e. I/O operations) it consumes resources that need to be freed at some point. It is also an extension of AbstractApplicationContext which implements Closable. Thus, it's got a close() method and can be used in a try-with-resources statement.

try (ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("META-INF/userLibrary.xml")) {
service = context.getBean(UserLibrary.class);
}

Whether you actually need to create this context is a different question (you linked to it), I'm not gonna comment on that.

It's true that the context is closed implicitly when the application is stopped but that's not good enough. Eclipse is right, you need to take measures to close it manually for other cases in order to avoid classloader leaks.

Resource leak: 'context' is never closed的更多相关文章

  1. Eclipse用java.util.Scanner时出现Resource leak: 'in' is never closed

    Resource leak: 'in' is never closed : 直译为资源泄漏,‘in’一直没被关闭. 由于声明了数据输入扫描仪(Scanner in),从而获得了配置内存,但是结束时却没 ...

  2. Java关于Resource leak: 's' is never closed的问题

    Resource leak: 's' is never closed的问题 问题:在编写Java时出现了Resource leak: 's' is never closed的问题,也就是对象s下面的波 ...

  3. Spring applicationContext爆出警告“Resource leak: 'applicationContext' is never closed”

    ApplicationContext applicationContext = new ClassPathXmlApplicationContext(xmlPath); 此处applicationCo ...

  4. Android Memory/Resource Leak总结

    Android的内存/资源泄露,不容易发现,又会引发app甚至是system的一系列问题. 在这里我根据以往碰到的相关问题,总结出了一些检测和修改方法. *有可能造成memory leak的代码是Fr ...

  5. 【Spring】初始化Spring IoC容器(非Web应用),并获取Bean

    参考文章 Introduction to the Spring IoC container and beans BeanFactory 和ApplicationContext(Bean工厂和应用上下文 ...

  6. spring Stack Overflow

    1. ApplicationContext 不关闭,资源泄露问题: Spring ApplicationContext - Resource leak: 'context' is never clos ...

  7. java 报错及解决

    java文件编译报错:error: unmappable character for encoding ASCII 解决: 编译时:javac -encoding utf-8 TestJava.jav ...

  8. Java用Scanner类获取用户输入

    用Java编写程序时,有些数据需要用户输入,这个时候需要调用java提供的Scanner类,这个类在包java.util下,比如求一个矩形的面积,简单的看一下用法: import java.util. ...

  9. Spring 入门 Ioc-Xml

    通过一个小例子演视怎么通过 Spring 往程序中注入对象,而非手动 new 对象. 一.导入 Spring 所需要的包 spring-framework-2.5.6 版需要导入以下包: 1.---- ...

随机推荐

  1. Vue基本应用

    1.  returnDetail.$mount('#returnDetail');  不用el 直接可以绑定数据到页面的id上 作用区域不能交叠多个vue 实体 否则后面的vue 实体会失效. 2. ...

  2. ngrok

    为什么要使用ngrok?/ngrok 作为一个Web开发者,我们有时候会需要临时地将一个本地的Web网站部署到外网,以供它人体验评价或协助调试等等,通常我们会这么做: 找到一台运行于外网的Web服务器 ...

  3. UI-切圆角、透明度、取消按钮点击高亮效果、按钮文字带下划线

    一.切UIView的某个角为圆角 如果需要将UIView的4个角全部都为圆角,做法相当简单,只需设置其Layer的cornerRadius属性即可(项目需要使用QuartzCore框架).而若要指定某 ...

  4. 易企秀微场景2016最新完整版V10.5,小编亲测修复众多错误

    易企秀V10.5更新说明1.修复拨号英文错误2.修复转送场景问题3.修复设置场景密码乱码问题4.修复前台批量删除客户图片5.修复数据收集分页问题6.修复图片分类错乱问题7.修复音乐和特效冲突问题8.修 ...

  5. NSURLSession网络请求

    个人感觉在网上很难找到很简单的网络请求.或许是我才疏学浅 ,  所有就有了下面这一段 , 虽然都是代码 , 但是全有注释 . //1/获取文件访问路径 NSString *path=@"ht ...

  6. web移动端开发技巧与注意事项汇总

    一.meta的使用 1.<meta name="viewport" content="width=device-width,initial-scale=1.0, m ...

  7. win2003 Enterprise x64 Edtion中的DCOM服务找不到WORD应用程序

    打开注册表,找到以下健值 HKEY_CLASSES_ROOT\AppID\{00020906-0000-0000-C000-000000000046} HKEY_CLASSES_ROOT\CLSID\ ...

  8. JQuery plugin ---- simplePagination.js API

    CSS Themes "light-theme" "dark-theme" "compact-theme" How To Use Step ...

  9. jQuery 上传头像插件Jcrop的实例

    兼容:ie6+,FF,chrome等 示例图: CSS:     说明:图像比例为110:135     下载包里有 jquery.Jcrop.css          .jc-demo-box{po ...

  10. log4j:ERROR Failed to rename [/log/xxx.log] to [/log/xxx.log.2016-11-23.log]

    Log4j报错: log4j:ERROR Failed to rename [/log/xxx.log] to [/log/xxx.log.2016-11-23.log] google了一下发现是个b ...