使用spring-mongo关闭mongo连接的正确方法是什么? [英] What is the correct way to close the mongo connection using spring-mongo?

查看:255
本文介绍了使用spring-mongo关闭mongo连接的正确方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Web应用程序中使用spring-mongo.当我在Tomcat7中取消部署应用程序时,会发生内存泄漏.我怀疑这可能是我没有明确关闭的Mongo对象.我想知道关闭它的正确方法(和位置).

I am using spring-mongo in my webapp. When I undeploy my application in Tomcat7, there is a memory leak. I suspect that it might be the Mongo object that I didn't explicitly close. I would like to know what is the correct way (and location) to close it.

推荐答案

这样的事情如何?

@Component
public class MongoDBManager {

  @Autowired
  Mongo mongo;

  @PreDestroy
  public void shutdown() {
    mongo.close();
  }
}

这篇关于使用spring-mongo关闭mongo连接的正确方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆