从 4.x 到 5.x 的迁移指南
Spring Data MongoDB 5.x 需要 MongoDB Java 驱动 5.6+
要了解更多关于驱动版本的信息,请访问 MongoDB 文档。
UUID 表示更改
Spring Data 不再通过其配置支持类、工厂 Bean 或 XML 命名空间来默认设置 UUID。
为了持久化 UUID 值,必须显式设置 UuidRepresentation。
-
Java
-
XML
@Configuration
static class Config extends AbstractMongoClientConfiguration {
@Override
protected void configureClientSettings(MongoClientSettings.Builder builder) {
builder.uuidRepresentation(UuidRepresentation.STANDARD);
}
// ...
}
<mongo:mongo-client>
<mongo:client-settings uuid-representation="STANDARD"/>
</mongo:mongo-client>
BigInteger/BigDecimal 转换更改
Spring Data 不再通过其配置支持类来默认设置 BigInteger/BigDecimal 转换。为了持久化这些值,必须显式设置默认的 BigDecimalRepresentation。
@Configuration
static class Config extends AbstractMongoClientConfiguration {
@Override
protected void configureConverters(MongoConverterConfigurationAdapter configAdapter) {
configAdapter.bigDecimal(BigDecimalRepresentation.DECIMAL128);
}
// ...
}
从先前版本升级的用户可以选择 BigDecimalRepresentation.STRING 作为默认值以保留之前的行为。
DefaultMessageListenerContainer 自动启动
可用于监听例如更改流的 DefaultMessageListenerContainer 现在将其 SmartLifecycle 自动启动默认为 true。
JMX 支持已停止。
我们建议切换到 Spring Boot Actuator 端点。