Litote / kmongo

[deprecated] KMongo - a Kotlin toolkit for Mongo
https://litote.org/kmongo/
Apache License 2.0
781 stars 75 forks source link

The problem is in new versions of KMongo when working with Spring #378

Closed KaRtoHHka closed 2 years ago

KaRtoHHka commented 2 years ago

I am creating a telegram bot using Kotlin, Spring and KMongo While I was working on the KMongo 4.3.0 version, everything worked, but as soon as I try to upgrade to the higher versions, I get an error

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'webHookController' defined in file [C:\Users\krugl\IdeaProjects\menshikova_bot\build\classes\kotlin\main\kartohhka\menshikova\bot\WebHookController.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'telegramBot' defined in kartohhka.menshikova.bot.appconfig.BotConfig: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [kartohhka.menshikova.bot.appconfig.botapi.MenshikovaTelegramBot]: Factory method 'telegramBot' threw exception; nested exception is java.lang.NoClassDefFoundError: org/bson/internal/CodecRegistryHelper
    at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:800) ~[spring-beans-5.3.16.jar:5.3.16]
    at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:229) ~[spring-beans-5.3.16.jar:5.3.16]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1372) ~[spring-beans-5.3.16.jar:5.3.16]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1222) ~[spring-beans-5.3.16.jar:5.3.16]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582) ~[spring-beans-5.3.16.jar:5.3.16]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.16.jar:5.3.16]
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.16.jar:5.3.16]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.16.jar:5.3.16]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.16.jar:5.3.16]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.16.jar:5.3.16]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:953) ~[spring-beans-5.3.16.jar:5.3.16]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918) ~[spring-context-5.3.16.jar:5.3.16]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) ~[spring-context-5.3.16.jar:5.3.16]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145) ~[spring-boot-2.6.4.jar:2.6.4]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:740) ~[spring-boot-2.6.4.jar:2.6.4]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:415) ~[spring-boot-2.6.4.jar:2.6.4]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) ~[spring-boot-2.6.4.jar:2.6.4]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1312) ~[spring-boot-2.6.4.jar:2.6.4]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1301) ~[spring-boot-2.6.4.jar:2.6.4]
    at kartohhka.menshikova.bot.MenshikovaBotApplicationKt.main(MenshikovaBotApplication.kt:21) ~[main/:na]
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na]
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
    at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na]
    at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) ~[spring-boot-devtools-2.6.4.jar:2.6.4]
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'telegramBot' defined in kartohhka.menshikova.bot.appconfig.BotConfig: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [kartohhka.menshikova.bot.appconfig.botapi.MenshikovaTelegramBot]: Factory method 'telegramBot' threw exception; nested exception is java.lang.NoClassDefFoundError: org/bson/internal/CodecRegistryHelper
    at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:658) ~[spring-beans-5.3.16.jar:5.3.16]
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:486) ~[spring-beans-5.3.16.jar:5.3.16]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1352) ~[spring-beans-5.3.16.jar:5.3.16]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1195) ~[spring-beans-5.3.16.jar:5.3.16]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582) ~[spring-beans-5.3.16.jar:5.3.16]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.16.jar:5.3.16]
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.16.jar:5.3.16]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.16.jar:5.3.16]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.16.jar:5.3.16]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.16.jar:5.3.16]
    at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276) ~[spring-beans-5.3.16.jar:5.3.16]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1389) ~[spring-beans-5.3.16.jar:5.3.16]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1309) ~[spring-beans-5.3.16.jar:5.3.16]
    at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:887) ~[spring-beans-5.3.16.jar:5.3.16]
    at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:791) ~[spring-beans-5.3.16.jar:5.3.16]
    ... 24 common frames omitted
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [kartohhka.menshikova.bot.appconfig.botapi.MenshikovaTelegramBot]: Factory method 'telegramBot' threw exception; nested exception is java.lang.NoClassDefFoundError: org/bson/internal/CodecRegistryHelper
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.3.16.jar:5.3.16]
    at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653) ~[spring-beans-5.3.16.jar:5.3.16]
    ... 38 common frames omitted
Caused by: java.lang.NoClassDefFoundError: org/bson/internal/CodecRegistryHelper
    at com.mongodb.client.internal.MongoClientImpl.<init>(MongoClientImpl.java:79) ~[mongodb-driver-sync-4.4.2.jar:na]
    at com.mongodb.client.internal.MongoClientImpl.<init>(MongoClientImpl.java:65) ~[mongodb-driver-sync-4.4.2.jar:na]
    at com.mongodb.client.MongoClients.create(MongoClients.java:108) ~[mongodb-driver-sync-4.4.2.jar:na]
    at org.litote.kmongo.KMongo.createClient(KMongo.kt:76) ~[kmongo-core-4.7.1.jar:na]
    at kartohhka.menshikova.bot.controller.DBController.<clinit>(DBController.kt:18) ~[main/:na]
    at kartohhka.menshikova.bot.appconfig.BotConfig.telegramBot(BotConfig.kt:22) ~[main/:na]
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na]
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
    at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na]
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.3.16.jar:5.3.16]
    ... 39 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.bson.internal.CodecRegistryHelper
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641) ~[na:na]
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188) ~[na:na]
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520) ~[na:na]
    ... 50 common frames omitted

Process finished with exit code 0

Dependencies

testImplementation(kotlin("test"))
    implementation("org.springframework.boot:spring-boot-starter-web")
    implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
    implementation("org.jetbrains.kotlin:kotlin-reflect")
    implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
    implementation ("org.telegram:telegrambots-spring-boot-starter:6.1.0")
    implementation ("org.telegram:telegrambots-meta:6.1.0")
    implementation("org.projectlombok:lombok:1.18.24")
    testImplementation ("de.flapdoodle.embed:de.flap-doodle.embed.mongo:3.4.3")
    implementation ("org.springframework.boot:spring-boot-configuration-processor:2.7.4")
    implementation ("org.springframework.boot:spring-boot-starter-data-mongodb:2.7.4")
    developmentOnly("org.springframework.boot:spring-boot-devtools")
    testImplementation("org.springframework.boot:spring-boot-starter-test")

    implementation("org.mongodb:bson:4.7.1")

    implementation("com.vdurmont:emoji-java:5.1.1")
    implementation ("org.springframework.boot:spring-boot-maven-plugin:2.7.4")

DBController

object DBController {

    private val client = KMongo.createClient() //get com.mongodb.MongoClient new instance

    private val database = client.getDatabase("menshikova_bot") //normal java driver usage

    private val botDoc = database.getCollection<BotConf>("botconf")
    private val userDoc = database.getCollection<User>("user")

    fun getBotDoc(): MongoCollection<BotConf> {
        return botDoc
    }

    fun getUserDoc(): MongoCollection<User> {
        return userDoc
    }
}
zigzago commented 2 years ago

Look at this:

at com.mongodb.client.internal.MongoClientImpl.<init>(MongoClientImpl.java:79) ~[mongodb-driver-sync-4.4.2.jar:na]

You have to force the mongo client driver to 4.7.1

HTH

KaRtoHHka commented 2 years ago

Look at this:

at com.mongodb.client.internal.MongoClientImpl.<init>(MongoClientImpl.java:79) ~[mongodb-driver-sync-4.4.2.jar:na]

You have to force the mongo client driver to 4.7.1

HTH

I added

implementation("org.mongodb:mongodb-driver-sync:4.7.1") But it didn't help, or is it the wrong thing?

KaRtoHHka commented 2 years ago

Ok, Now the error is a little different

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'webHookController' defined in file [C:\Users\krugl\IdeaProjects\menshikova_bot\build\classes\kotlin\main\kartohhka\menshikova\bot\WebHookController.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'telegramBot' defined in kartohhka.menshikova.bot.appconfig.BotConfig: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [kartohhka.menshikova.bot.appconfig.botapi.MenshikovaTelegramBot]: Factory method 'telegramBot' threw exception; nested exception is java.lang.IllegalAccessError: class org.litote.kmongo.KMongo tried to access method 'void org.bson.internal.OverridableUuidRepresentationCodecRegistry.<init>(org.bson.codecs.configuration.CodecProvider, org.bson.UuidRepresentation)' (org.litote.kmongo.KMongo and org.bson.internal.OverridableUuidRepresentationCodecRegistry are in unnamed module of loader 'app')
    at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:800) ~[spring-beans-5.3.16.jar:5.3.16]
    at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:229) ~[spring-beans-5.3.16.jar:5.3.16]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1372) ~[spring-beans-5.3.16.jar:5.3.16]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1222) ~[spring-beans-5.3.16.jar:5.3.16]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582) ~[spring-beans-5.3.16.jar:5.3.16]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.16.jar:5.3.16]
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.16.jar:5.3.16]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.16.jar:5.3.16]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.16.jar:5.3.16]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.16.jar:5.3.16]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:953) ~[spring-beans-5.3.16.jar:5.3.16]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918) ~[spring-context-5.3.16.jar:5.3.16]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) ~[spring-context-5.3.16.jar:5.3.16]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145) ~[spring-boot-2.6.4.jar:2.6.4]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:740) ~[spring-boot-2.6.4.jar:2.6.4]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:415) ~[spring-boot-2.6.4.jar:2.6.4]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) ~[spring-boot-2.6.4.jar:2.6.4]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1312) ~[spring-boot-2.6.4.jar:2.6.4]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1301) ~[spring-boot-2.6.4.jar:2.6.4]
    at kartohhka.menshikova.bot.MenshikovaBotApplicationKt.main(MenshikovaBotApplication.kt:21) ~[main/:na]
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na]
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
    at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na]
    at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) ~[spring-boot-devtools-2.6.4.jar:2.6.4]
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'telegramBot' defined in kartohhka.menshikova.bot.appconfig.BotConfig: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [kartohhka.menshikova.bot.appconfig.botapi.MenshikovaTelegramBot]: Factory method 'telegramBot' threw exception; nested exception is java.lang.IllegalAccessError: class org.litote.kmongo.KMongo tried to access method 'void org.bson.internal.OverridableUuidRepresentationCodecRegistry.<init>(org.bson.codecs.configuration.CodecProvider, org.bson.UuidRepresentation)' (org.litote.kmongo.KMongo and org.bson.internal.OverridableUuidRepresentationCodecRegistry are in unnamed module of loader 'app')
    at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:658) ~[spring-beans-5.3.16.jar:5.3.16]
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:486) ~[spring-beans-5.3.16.jar:5.3.16]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1352) ~[spring-beans-5.3.16.jar:5.3.16]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1195) ~[spring-beans-5.3.16.jar:5.3.16]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582) ~[spring-beans-5.3.16.jar:5.3.16]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.16.jar:5.3.16]
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.16.jar:5.3.16]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.16.jar:5.3.16]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.16.jar:5.3.16]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.16.jar:5.3.16]
    at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276) ~[spring-beans-5.3.16.jar:5.3.16]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1389) ~[spring-beans-5.3.16.jar:5.3.16]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1309) ~[spring-beans-5.3.16.jar:5.3.16]
    at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:887) ~[spring-beans-5.3.16.jar:5.3.16]
    at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:791) ~[spring-beans-5.3.16.jar:5.3.16]
    ... 24 common frames omitted
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [kartohhka.menshikova.bot.appconfig.botapi.MenshikovaTelegramBot]: Factory method 'telegramBot' threw exception; nested exception is java.lang.IllegalAccessError: class org.litote.kmongo.KMongo tried to access method 'void org.bson.internal.OverridableUuidRepresentationCodecRegistry.<init>(org.bson.codecs.configuration.CodecProvider, org.bson.UuidRepresentation)' (org.litote.kmongo.KMongo and org.bson.internal.OverridableUuidRepresentationCodecRegistry are in unnamed module of loader 'app')
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.3.16.jar:5.3.16]
    at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653) ~[spring-beans-5.3.16.jar:5.3.16]
    ... 38 common frames omitted
Caused by: java.lang.IllegalAccessError: class org.litote.kmongo.KMongo tried to access method 'void org.bson.internal.OverridableUuidRepresentationCodecRegistry.<init>(org.bson.codecs.configuration.CodecProvider, org.bson.UuidRepresentation)' (org.litote.kmongo.KMongo and org.bson.internal.OverridableUuidRepresentationCodecRegistry are in unnamed module of loader 'app')
    at org.litote.kmongo.KMongo.createRegistry(KMongo.kt:89) ~[kmongo-core-4.7.1.jar:na]
    at org.litote.kmongo.KMongo.createClient(KMongo.kt:79) ~[kmongo-core-4.7.1.jar:na]
    at org.litote.kmongo.KMongo.createClient(KMongo.kt:61) ~[kmongo-core-4.7.1.jar:na]
    at org.litote.kmongo.KMongo.createClient(KMongo.kt:51) ~[kmongo-core-4.7.1.jar:na]
    at org.litote.kmongo.KMongo.createClient(KMongo.kt:43) ~[kmongo-core-4.7.1.jar:na]
    at kartohhka.menshikova.bot.controller.DBController.<clinit>(DBController.kt:15) ~[main/:na]
    at kartohhka.menshikova.bot.appconfig.BotConfig.telegramBot(BotConfig.kt:22) ~[main/:na]
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na]
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
    at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na]
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.3.16.jar:5.3.16]
    ... 39 common frames omitted

Process finished with exit code 0
zigzago commented 2 years ago

Use mvn dependency:tree or ./gradlew dependencies to look at your dependencies at runtime.All mongo dependencies (included bson) should be 4.7.1

KaRtoHHka commented 2 years ago

Everywhere 4.7.1 except the block spring-boot-starter-data-mongodb:2.7.4 and this one

org.mongodb:mongodb-driver-sync:4.7.1
|    +--- org.mongodb:bson:4.7.1 -> 4.4.2
|    \--- org.mongodb:mongodb-driver-core:4.7.1 -> 4.4.2
|         \--- org.mongodb:bson:4.4.2
zigzago commented 2 years ago

You have to force org.mongodb:bson & org.mongodb:mongodb-driver-core in 4.7.1

KaRtoHHka commented 2 years ago

Thank you, it helped, here are my dependencies in the end

dependencies {
    testImplementation(kotlin("test"))
    implementation("org.springframework.boot:spring-boot-starter-web")
    implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
    implementation("org.jetbrains.kotlin:kotlin-reflect")
    implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
    implementation ("org.telegram:telegrambots-spring-boot-starter:6.1.0")
    implementation ("org.telegram:telegrambots-meta:6.1.0")
    implementation("org.projectlombok:lombok:1.18.24")
    implementation ("org.springframework.boot:spring-boot-configuration-processor:2.7.4")
    implementation ("org.springframework.boot:spring-boot-starter-data-mongodb:2.7.4")
    developmentOnly("org.springframework.boot:spring-boot-devtools")
    testImplementation("org.springframework.boot:spring-boot-starter-test")
    implementation("org.mongodb:bson:4.7.1")
    implementation("org.mongodb:mongodb-driver-core:4.7.1")
    implementation("org.mongodb:mongodb-driver-sync:4.7.1")
    implementation("org.litote.kmongo:kmongo:4.7.1")
    implementation("com.vdurmont:emoji-java:5.1.1")
    implementation ("org.springframework.boot:spring-boot-maven-plugin:2.7.4")
}