How to initialize MongoClient once in Spring Boot and use its methods?
Here are couple of ways of creating an instance of MongoClient, configuring and using it within the Spring Boot application. (1) Registering a Mongo Instance using Java-based Metadata: @Configuration public class AppConfig { public @Bean MongoClient mongoClient() { return MongoClients.create(); } } Usage from CommandLineRunner‘s run method (all examples are run similarly): @Autowired MongoClient mongoClient; … Read more