0

what is the best way to dispose DocumentNodeStore in a Spring boot application when the server shutdowns?

@Configuration
@Profile("production")
public class MongoRepositoryInitializer {

.
.
.

    @Bean
    public DocumentNodeStore documentNodeStore(MongoClient mongoClient, MongoBlobStore mongoBlobStore) {
        return MongoDocumentNodeStoreBuilder
                .newMongoDocumentNodeStoreBuilder().setMongoDB(mongoClient, mongoDbName, 16)
                .setBlobStore(mongoBlobStore)
                .build();
    }
}

where should I call documentNodeStore.dispose() ? is this enough to clean up all mongo related staffs ?

mhrsalehi
  • 1,124
  • 1
  • 12
  • 29
  • can I define I `finalizer` bean and inject `documentNodeStore` into it, and call `dispose` method in a method of `finalizer` annotated with @destroy related annotation? – mhrsalehi May 04 '20 at 05:07
  • of course I can! (and I did, and I am not getting errors in the next start-up anymore ), I mean what is the best practice – mhrsalehi May 04 '20 at 05:22
  • Don't... The `finalize` method is a bad place to do that. Instead specify the `destroyMethod` on the `@Bean` annotation. Which will be called when the bean is destroyed. – M. Deinum May 04 '20 at 09:17

0 Answers0