How about something like this:
@Component
public class MongoDBManager {
@Autowired
Mongo mongo;
@PreDestroy
public void shutdown() {
mongo.close();
}
}
質問
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.
解決
How about something like this:
@Component
public class MongoDBManager {
@Autowired
Mongo mongo;
@PreDestroy
public void shutdown() {
mongo.close();
}
}