- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在使用 Kotlin 在 Micronaut 中为 MongoDB 配置对象映射时遇到了一些困难。我收到如下错误:
Decoding into a 'Asset' failed with the following exception:
Cannot find a public constructor for 'Asset'.
A custom Codec or PojoCodec may need to be explicitly configured and registered to handle this type. org.bson.codecs.configuration.CodecConfigurationException: An exception occurred when decoding using the AutomaticPojoCodec. Decoding into a 'Asset' failed with the following exception:
Cannot find a public constructor for 'Asset'.
A custom Codec or PojoCodec may need to be explicitly configured and registered to handle this type.
使用 KMongo,这很容易。然而,Micronaut 注入(inject)的 MongoClient 没有 KMongo 的编解码器注册表。
我可以让它按如下方式工作:
val db: MongoDatabase by lazy {
val codecRegistry = ClassMappingType.codecRegistry(MongoClientSettings.getDefaultCodecRegistry())
client.getDatabase("db-name").withCodecRegistry(codecRegistry)
}
此代码直接取自 KMongo。 (顺便说一句,使用 database.withKMongo()
导致了同样的错误)
虽然这可行,但我希望让 Micronaut 使用 KMongo 创建客户端,或者让它像上面那样使用其编解码器,使用配置 (application.yml)。
此处提到了一个codec-registry
设置:https://micronaut-projects.github.io/micronaut-mongodb/latest/guide/configurationreference.html ,但我不知道在该设置中输入什么才能使其正常工作。
感谢任何帮助!
最佳答案
您可以简单地将编解码器注册表定义为一个 bean。由于您无法控制正在注册的类,因此您可以创建一个工厂
@Factory
class KMongoFactory {
@Singleton
fun kCodecRegistry(): CodecRegistry {
return ClassMappingType.codecRegistry(MongoClientSettings.getDefaultCodecRegistry());
}
}
类似上面的东西应该可以做到
编辑:请注意 MongoClients.getDefaultCodecRegistry()
是默认添加的
关于mongodb - 如何使用 Micronaut 和 Kotlin + KMongo 为 MongoDB 配置对象映射?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54714058/
由于遗留原因,我们有很多代码位于存储过程下。类似于Spring data(@Procedure),micronaut中有没有调用存储过程的方法。我是否必须注入(inject) entityManage
我从 CLI 创建了一个新的 Micronaut 并进行了一些修改,然后意识到我可以从 cli 添加功能,但它似乎只是在调用 create-app 时的一个选项。 创建应用程序后,有没有办法从命令行添
我使用指南 send mail in micronaut 将 AWS SES API 集成到了我的 Micronaut Groovy 应用程序中如果我直接为属性赋值,我就可以发送邮件。 我想让它配置驱
寻求帮助以了解 Micronaut 2 的正确模式。 现在,所有 Controller 方法都默认在 NIO Eventloop 线程上运行。文档警告不要在此线程上执行任何阻塞调用,而是将其卸载到线程
我的客户应该从 Controller 收到一个文件。我不知道应该如何实现客户端。这是我的 Controller : @Get("/{databaseName}") MutableHttpRespons
如何为 micronaut 微服务设置上下文路径?我想做一些类似于 Spring Framework 中可用的操作,您可以在其中设置“server.servlet.contextPath”属性。我在
我正在开发一个 cli 应用程序,它可以接受一些选项:--info、--debug、--trace。我想使用参数来设置整个应用程序的日志记录级别。是否有捷径可寻?这是我到目前为止所尝试过的:
我正在评估 micronaut 并尝试移植一个小型应用程序作为试点项目。我遇到了处理数据源/存储库的障碍。 我有以下application.yml: micronaut: application:
我正在使用 Micronaut 的声明性 http 客户端从 API 检索数据。但是现在我需要在运行时动态更改服务器地址。这可能吗? 例子: @Client("${http.client.url}")
我需要在我的请求中将参数设置为不需要。 我试过: @Get(value = "/list/{username}") HttpResponse list(String username, @Quer
有没有办法配置 Micronaut 断路器,使其不针对特定的 HTTP 状态代码打开?例如,如果我查找某个项目但未找到该项目,则服务器可能会返回 HTTP 状态 404。这可能是一个完全有效的响应,我
我们一直在评估 Micronaut 框架,并希望使用 Apache Camel 库。我没有看到与 Apache Camel 的特定集成。 Apache Camel 库确实支持一组注释。 问题 我们可以
Micronaut 需要大约 75 秒来启动它的 hello-world 示例项目是否正常?这似乎与描述框架的方式非常不一致。我在具有良好规范的 MacBook Pro 上运行它,并且该项目是按照 M
我的 Controller 中有一个带有不同参数的 get 函数: myinterface.java : public interface MyInterface { @Get(value =
我不确定这是 Micronaut 还是 AWS Gateway 问题。任何帮助都会很棒。 我正在尝试使用 Micronaut 框架创建一个 Lambda 函数,该函数通过 AWS API 网关返回 p
我想利用 Micronaut 的“声明式 HTTP 客户端”功能。我很难理解如何传递动态 header 值,并且想知道这是否可能。考虑以下示例: package com.example; import
我对 Micronaut 很陌生,我只是想问,因为我无法从官方文档中得到任何答案 我的文件夹根目录中有一个 .env 文件。这是我的 .env PORT=8081 我试图访问 application.
假设我有 MotoDao 和 CarDao,它们都是 VehicleDao 接口(interface)的实现。 如何使用 micronuat 将两者都注入(inject)到一个类中? 我希望如下所示:
有谁知道如何配置 Eclipse IDE 以使用 micronaut-inject-java 注释处理器?我有一个指定 micronaut 注释处理器的 Gradle 构建文件,并且我的单元测试在 G
我正在使用 Micronaut、Micronaut Data、JPA、Postgres 和 GraalVM 开发一个新示例,如下所示 https://github.com/rmondejar/micr
我是一名优秀的程序员,十分优秀!