Closed szpak closed 10 years ago
Look into the code… It doesn’t matter if you call close()
on an instance of MongoClient, or directly stop()
on the underlying MongodExecutable. It’s called anyway so it’s useless to expose the MongodExecutable just to call stop()
on it.
It’s actually unnecessary to explicitly close/stop a Mongo process at all. I’ve been testing it and discovered, that Mongo process is always “somehow” (Embed Process is very smart) stopped before the destroy() method is called by Spring, so it has actually no effect here.
Anyway, the EmbeddedMongoFactoryBean still implements the destroy()
method that explicitly closes Mongo instance on a context shutdown, just to be sure. The new EmbeddedMongoBuilder, on the other hand, does not implement this functionality, because it can’t do that (not in this way). The builder is never registered in a context, it’s just a… eh… plain builder. However, it’s not problem to use @PreDestroy
in a @Configuration
class to close it explicitly, if needed.
By the way, are you using the “embedded” Mongo just in integration tests? I don’t understand why you’re doing hot redeploy here.
@szpak Any comment?
Before 1.2 there were executed MongoExecutable.stop() on Spring context shutdown. In 1.2 it was removed (there is only closed MongoClient) which inter alia affects closing mongod process on an application hot redeploy on Tomcat.