Quarkus 应用程序找不到 MongoDB 个客户端的编解码器
Quarkus application cannot find codec for MongoDB Clients
运行 具有 MongoDB (Panache) 的 quarkus 应用程序在启动时显示警告,例如:
WARN [io.qua.mon.run.MongoClients] (main) Unable to load the property codec provider class org.bson.codecs.pojo.EnumPropertyCodecProvider: java.lang.NoSuchMethodException: org.bson.codecs.pojo.EnumPropertyCodecProvider.<init>()
at java.base/java.lang.Class.getConstructor0(Class.java:3349)
at java.base/java.lang.Class.getConstructor(Class.java:2151)
at io.quarkus.mongodb.runtime.MongoClients.getPropertyCodecProviders(MongoClients.java:440)
at io.quarkus.mongodb.runtime.MongoClients.configureCodecRegistry(MongoClients.java:332)
at io.quarkus.mongodb.runtime.MongoClients.createMongoConfiguration(MongoClients.java:255)
at io.quarkus.mongodb.runtime.MongoClients.createReactiveMongoClient(MongoClients.java:115)
at io.quarkus.mongodb.runtime.MongoClientRecorder.reactiveMongoClientSupplier(MongoClientRecorder.java:57)
at io.quarkus.deployment.steps.MongoClientProcessor$generateClientBeans-1756432087.deploy_0(MongoClientProcessor$generateClientBeans-1756432087.zig:96)
at io.quarkus.deployment.steps.MongoClientProcessor$generateClientBeans-1756432087.deploy(MongoClientProcessor$generateClientBeans-1756432087.zig:40)
at io.quarkus.runner.ApplicationImpl.doStart(ApplicationImpl.zig:666)
at io.quarkus.runtime.Application.start(Application.java:101)
at io.quarkus.runtime.ApplicationLifecycleManager.run(ApplicationLifecycleManager.java:101)
at io.quarkus.runtime.Quarkus.run(Quarkus.java:66)
at io.quarkus.runtime.Quarkus.run(Quarkus.java:42)
at io.quarkus.runtime.Quarkus.run(Quarkus.java:119)
at io.quarkus.runner.GeneratedMain.main(GeneratedMain.zig:29)
然后是从数据库中获取数据的操作(例如查找)。在类似于这样的循环中生成 Whosebug 异常:
at org.bson.internal.LazyCodec.encode(LazyCodec.java:38)
at org.bson.BsonDocumentWrapper.getUnwrapped(BsonDocumentWrapper.java:195)
at org.bson.BsonDocumentWrapper.entrySet(BsonDocumentWrapper.java:165)
at org.bson.codecs.BsonDocumentCodec.encode(BsonDocumentCodec.java:112)
at org.bson.codecs.BsonDocumentCodec.encode(BsonDocumentCodec.java:42)
at org.bson.codecs.BsonCodec.encode(BsonCodec.java:55)
at org.bson.codecs.BsonCodec.encode(BsonCodec.java:33)
at org.bson.internal.LazyCodec.encode(LazyCodec.java:38)
at org.bson.BsonDocumentWrapper.getUnwrapped(BsonDocumentWrapper.java:195)
at org.bson.BsonDocumentWrapper.entrySet(BsonDocumentWrapper.java:165)
at org.bson.codecs.BsonDocumentCodec.encode(BsonDocumentCodec.java:112)
at org.bson.codecs.BsonDocumentCodec.encode(BsonDocumentCodec.java:42)
映射的对象包含一个 ObjectId 标识符。而那些bean是在一个单独的项目中定义的,有jandex插件来索引bean
直接在项目 POM 文件中定义的来自 Quarkus 的依赖项是:
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-arc</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-mongodb-panache</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-rest-client</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-fault-tolerance</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-jackson</artifactId>
</dependency>
我发现了问题。错误地将 bson 库添加到 jandex 索引中。
将其从索引中删除可解决问题。
在我们的例子中,它是在应用程序属性上声明的:
quarkus.index-dependency.bson.group-id=org.mongodb
quarkus.index-dependency.bson.artifact-id=bson
我删除了那些行,该项目可以运行,但我们看到编译警告
[WARNING] [io.quarkus.deployment.steps.ReflectiveHierarchyStep] Unable to properly register the hierarchy of the following classes for reflection as they are not in the Jandex index:
- org.bson.types.ObjectId (source: RestClientProcessor > com.saaskun.api...)
运行 具有 MongoDB (Panache) 的 quarkus 应用程序在启动时显示警告,例如:
WARN [io.qua.mon.run.MongoClients] (main) Unable to load the property codec provider class org.bson.codecs.pojo.EnumPropertyCodecProvider: java.lang.NoSuchMethodException: org.bson.codecs.pojo.EnumPropertyCodecProvider.<init>()
at java.base/java.lang.Class.getConstructor0(Class.java:3349)
at java.base/java.lang.Class.getConstructor(Class.java:2151)
at io.quarkus.mongodb.runtime.MongoClients.getPropertyCodecProviders(MongoClients.java:440)
at io.quarkus.mongodb.runtime.MongoClients.configureCodecRegistry(MongoClients.java:332)
at io.quarkus.mongodb.runtime.MongoClients.createMongoConfiguration(MongoClients.java:255)
at io.quarkus.mongodb.runtime.MongoClients.createReactiveMongoClient(MongoClients.java:115)
at io.quarkus.mongodb.runtime.MongoClientRecorder.reactiveMongoClientSupplier(MongoClientRecorder.java:57)
at io.quarkus.deployment.steps.MongoClientProcessor$generateClientBeans-1756432087.deploy_0(MongoClientProcessor$generateClientBeans-1756432087.zig:96)
at io.quarkus.deployment.steps.MongoClientProcessor$generateClientBeans-1756432087.deploy(MongoClientProcessor$generateClientBeans-1756432087.zig:40)
at io.quarkus.runner.ApplicationImpl.doStart(ApplicationImpl.zig:666)
at io.quarkus.runtime.Application.start(Application.java:101)
at io.quarkus.runtime.ApplicationLifecycleManager.run(ApplicationLifecycleManager.java:101)
at io.quarkus.runtime.Quarkus.run(Quarkus.java:66)
at io.quarkus.runtime.Quarkus.run(Quarkus.java:42)
at io.quarkus.runtime.Quarkus.run(Quarkus.java:119)
at io.quarkus.runner.GeneratedMain.main(GeneratedMain.zig:29)
然后是从数据库中获取数据的操作(例如查找)。在类似于这样的循环中生成 Whosebug 异常:
at org.bson.internal.LazyCodec.encode(LazyCodec.java:38)
at org.bson.BsonDocumentWrapper.getUnwrapped(BsonDocumentWrapper.java:195)
at org.bson.BsonDocumentWrapper.entrySet(BsonDocumentWrapper.java:165)
at org.bson.codecs.BsonDocumentCodec.encode(BsonDocumentCodec.java:112)
at org.bson.codecs.BsonDocumentCodec.encode(BsonDocumentCodec.java:42)
at org.bson.codecs.BsonCodec.encode(BsonCodec.java:55)
at org.bson.codecs.BsonCodec.encode(BsonCodec.java:33)
at org.bson.internal.LazyCodec.encode(LazyCodec.java:38)
at org.bson.BsonDocumentWrapper.getUnwrapped(BsonDocumentWrapper.java:195)
at org.bson.BsonDocumentWrapper.entrySet(BsonDocumentWrapper.java:165)
at org.bson.codecs.BsonDocumentCodec.encode(BsonDocumentCodec.java:112)
at org.bson.codecs.BsonDocumentCodec.encode(BsonDocumentCodec.java:42)
映射的对象包含一个 ObjectId 标识符。而那些bean是在一个单独的项目中定义的,有jandex插件来索引bean
直接在项目 POM 文件中定义的来自 Quarkus 的依赖项是:
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-arc</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-mongodb-panache</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-rest-client</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-fault-tolerance</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-jackson</artifactId>
</dependency>
我发现了问题。错误地将 bson 库添加到 jandex 索引中。
将其从索引中删除可解决问题。
在我们的例子中,它是在应用程序属性上声明的:
quarkus.index-dependency.bson.group-id=org.mongodb
quarkus.index-dependency.bson.artifact-id=bson
我删除了那些行,该项目可以运行,但我们看到编译警告
[WARNING] [io.quarkus.deployment.steps.ReflectiveHierarchyStep] Unable to properly register the hierarchy of the following classes for reflection as they are not in the Jandex index:
- org.bson.types.ObjectId (source: RestClientProcessor > com.saaskun.api...)