Problem :
Exception in thread "main" org.bson.codecs.configuration.CodecConfigurationException: Can't find a codec for class java.time.LocalDate.
org.bson.codecs.configuration.CodecConfigurationException: Unable to get value for property
Solution :
Try creating your bean by this way to help POJO classes.
Exception in thread "main" org.bson.codecs.configuration.CodecConfigurationException: Can't find a codec for class java.time.LocalDate.
org.bson.codecs.configuration.CodecConfigurationException: Unable to get value for property
Solution :
Try creating your bean by this way to help POJO classes.
@Bean public MongoDatabase mongoDatabase() { try { CodecRegistry pojoCodecRegistry = fromRegistries(MongoClient.getDefaultCodecRegistry(), fromProviders(PojoCodecProvider.builder().automatic(true).build())); String connectionString = "mongodb+srv://" + username + ":" + password + "@" + host + "/" + database + ""; log.info("Connection String " + connectionString); MongoClientURI uri = new MongoClientURI(connectionString); MongoClient mongoClient = new MongoClient(uri); MongoDatabase database = mongoClient.getDatabase("mydb").withCodecRegistry(pojoCodecRegistry); return database; } catch (Exception e) { log.error("Error in Connection " + e); return null; } }
Comments
Post a Comment