Reputation: 235
Hi I am trying to use Shedlock for Spring Boot Mongo. The docs said it required Mongo JAva 3.7.0. I am currently using Spring spring-boot-starter-parent v 2.0.4, which had an older version of the driver, so upgraded to version 2.1.0.
Below is the code I have place to start the lock:
@Configuration
@EnableScheduling
@EnableSchedulerLock(defaultLockAtMostFor = "1m")
public class ApplicationConfiguration {
@Bean
public LockProvider lockProvider(MongoClient mongo) {
return new MongoLockProvider(mongo.getDatabase("hmrccalculation"));
}
}
Then my code is:
@Scheduled(cron = "I 0 0/5 * * * *")
@SchedulerLock(name = "lock", lockAtLeastFor = "1m")
public void process() {
LockAssert.assertLocked();
The error I get is:
"message":"Unexpected error occurred in scheduled
task.","stack":"org.bson.codecs.configuration.CodecConfigurationException: Can\'t find a
codec for class java.time.Instant.\nat
org.bson.codecs.configuration.CodecCache.getOrThrow(CodecCache.java:46)\nat
org.bson.codecs.configuration.ProvidersCodecRegistry.get(ProvidersCodecRegistry.java:63)\nat
org.bson.codecs.configuration.ProvidersCodecRegistry.get(ProvidersCodecRegistry.java:37)\nat
com.mongodb.client.model.BuildersHelper.encodeValue(BuildersHelper.java:35)\nat
com.mongodb.client.model.Updates$SimpleUpdate.toBsonDocument(Updates.java:442)\nat
com.mongodb.client.model.Updates$CompositeUpdate.toBsonDocument(Updates.java:605)\nat
com.mongodb.MongoCollectionImpl.toBsonDocument(MongoCollectionImpl.java:1074)\nat
com.mongodb.MongoCollectionImpl.executeFindOneAndUpdate(MongoCollectionImpl.java:766)\nat
com.mongodb.MongoCollectionImpl.findOneAndUpdate(MongoCollectionImpl.java:748)\nat
Upvotes: 0
Views: 1270
Reputation: 14303
You have to upgrade to mongo-java-driver 3.7.0. Spring Boot 2.1.0 contains an older version. You do not have to upgrade whole Spring Boot, just the one dependency.
Upvotes: 0