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

后端 未结 1 1176
盖世英雄少女心
盖世英雄少女心 2021-01-15 20:33

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 explicitl

相关标签:
1条回答
  • 2021-01-15 21:13

    How about something like this:

    @Component
    public class MongoDBManager {
    
      @Autowired
      Mongo mongo;
    
      @PreDestroy
      public void shutdown() {
        mongo.close();
      }
    }
    
    0 讨论(0)
提交回复
热议问题