spring-boot 2.3.6,如何设置mongo的UUID表示?

Bam*_*ylo 1 mongodb spring-data-mongodb spring-boot

我正在尝试升级到 spring-boot 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)

Run Code Online (Sandbox Code Playgroud)

尝试过定制

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)

Run Code Online (Sandbox Code Playgroud)

没有帮助,同样的例外。

在 spring-boot 2.3.6 中自定义 UUID 编解码器的正确方法是什么?

谢谢。

dan*_*tro 7

在 Spring Boot application.properties 上简单地告知:

spring.data.mongodb.uuid-representation=standard
Run Code Online (Sandbox Code Playgroud)