|
此版本仍在开发中,尚未被视为稳定版。如需最新稳定版本,请使用 Spring Data MongoDB 5.0.4! |
从 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 自动启动
现在,可用于监听例如变更流(Change Streams)的DefaultMessageListenerContainer,其SmartLifecycle自动启动默认值已设为true。
JMX 支持已停止。
我们建议切换到 Spring Boot Actuator 端点。