What is the correct way to close the mongo connection using spring-mongo?

最后都变了- 提交于 2019-12-01 10:50:55

问题


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.


回答1:


How about something like this:

@Component
public class MongoDBManager {

  @Autowired
  Mongo mongo;

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


来源:https://stackoverflow.com/questions/13721115/what-is-the-correct-way-to-close-the-mongo-connection-using-spring-mongo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!