Spring-Boot 2.3.6,如何为mongo设置UUID表示? [英] spring-boot 2.3.6, how to set UUID representation for mongo?
本文介绍了Spring-Boot 2.3.6,如何为mongo设置UUID表示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试升级到春靴2.3.6。我使用的是Spring-data MongoRepositories,没有直接调用MongoClient或MongoClient。
获取异常:
Caused by: org.bson.codecs.configuration.CodecConfigurationException: The uuidRepresentation has not been specified, so the UUID cannot be encoded.
at org.bson.codecs.UuidCodec.encode(UuidCodec.java:72)
at org.bson.codecs.UuidCodec.encode(UuidCodec.java:37)
at org.bson.codecs.EncoderContext.encodeWithChildContext(EncoderContext.java:91)
at org.bson.codecs.DocumentCodec.writeValue(DocumentCodec.java:198)
at org.bson.codecs.DocumentCodec.writeMap(DocumentCodec.java:212)
at org.bson.codecs.DocumentCodec.encode(DocumentCodec.java:154)
at org.bson.codecs.DocumentCodec.encode(DocumentCodec.java:45)
已尝试自定义
@Bean
public MongoClientSettingsBuilderCustomizer mongoDBDefaultSettings() {
return builder -> {
builder.uuidRepresentation(UuidRepresentation.JAVA_LEGACY);
};
}
没有帮助,相同的异常。
在SpringBoot 2.3.6中自定义UUID编解码器的正确方式是什么?
谢谢。
推荐答案
在Spring Boot应用程序上。属性只需通知:
spring.data.mongodb.uuid-representation=standard
这篇关于Spring-Boot 2.3.6,如何为mongo设置UUID表示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文