如何在 Spring 启动时禁用 GridFS MD5 计算?

How do I disable GridFS MD5 calculation in Spring Boot?

现在 GridFS 文件集合的 md5 属性已经过时,不需要驱动程序来计算它,所以我想禁用它以节省几毫秒......

MongoDB Java 驱动程序确实在 GridFSBucketImpl 中提供了一个选项 disableMD5,但是由于我使用的是 Spring 引导的 GridFsTemplate (spring-data-mongodb 2.1.2.RELEASE) 我没有直接访问它的权限。 GridFsTemplate 有一个方法 getGridFs() returns a GridFSBucket 为当前数据库和存储桶名称配置,但不幸的是这个方法是私有的所以我不能覆盖它。

那么我有什么选择呢?我是否必须覆盖所有 GridFsTemplate?我错过了某个地方的简单设置吗?我应该向 Spring 提交功能请求吗?

更新 显然 GridFsTemplate 并不意味着要扩展(尽管只需要 getGridFs 和几个要保护的字段)所以我最终创建了自己的 CustomGridFsTemplate,这几乎是准确的GridFsTemplate 的副本,除了我在 getGridFs 中调用 GridFSBucket.withDisableMD5(true)

我对此不是很满意,但它确实有效,我目前没有看到更好的选择。

更新 2 我已提交 Spring 功能请求,请为它投票! https://jira.spring.io/browse/DATAMONGO-2165

目前没有更好的办法。看起来您已提交 a ticket 以扩展 GridFsTemplate 以允许自定义。