spring-data-mongodb - 从反应式 GridFS 读取文件时出现 StackOverflowError
问题描述
我对 ReactiveGridFsTemplate 有疑问。我正在尝试读取使用旧 GridFS (com.mongodb.gridfs) 而不是新 GridFS (com.mongodb.client.gridfs.model.GridFS) 编写的 GridFS 文件,并将 UUID 作为 ID 而不是 ObjectId。读取 GridFS 文件元信息很顺利,但只要我想获得 ReactiveGridFsResource,它就会出现一个不错的新 MongoGridFSException(“用于此 GridFS 文件的自定义 id 类型”)。
罪魁祸首是下面来自 ReactiveGridFsTemplate 的代码,它调用 getObjectId() 而不是 getId()。它应该调用此方法还是可以将其重写为 getId() 方法?
public Mono<ReactiveGridFsResource> getResource(GridFSFile file) {
Assert.notNull(file, "GridFSFile must not be null!");
return Mono.fromSupplier(() -> {
GridFSDownloadStream stream = this.getGridFs().openDownloadStream(file.getObjectId());
return new ReactiveGridFsResource(file, BinaryStreamAdapters.toPublisher(stream, this.dataBufferFactory));
});
}
我破解了 ReactiveGridFsTemplate 以使用 getId() 而不是 getObjectId() 但现在它给了我一个 stackoverflow 异常。有人可以告诉我我做错了什么吗?
ReactiveGridFsTemplate reactiveGridFsTemplate = new ReactiveGridFsTemplate(mongoDbDFactory, operations.getConverter(), "nl.loxia.collectie.buitenlandbladen.dgn", 1024) {
public Mono<ReactiveGridFsResource> getResource(GridFSFile file) {
Assert.notNull(file, "GridFSFile must not be null!");
return Mono.fromSupplier(() -> {
GridFSDownloadStream stream = this.getGridFs().openDownloadStream(file.getId());
return new ReactiveGridFsResource(file, BinaryStreamAdapters.toPublisher(stream, this.dataBufferFactory));
});
}
};
var q = Query.query((Criteria.where("_id").is("5449d9e3-7f6d-47b7-957d-056842f190f7")));
List<DataBuffer> block = reactiveGridFsTemplate
.findOne(q)
.flatMap(reactiveGridFsTemplate::getResource)
.flux()
.flatMap(ReactiveGridFsResource::getDownloadStream)
.collectList()
.block();
堆栈跟踪:https ://gist.github.com/nickstolwijk/fa77681572db1d91941d85f6c845f2f4
此外,此代码由于 stackoverflow 异常而挂起。那是对的吗?
解决方案
推荐阅读
- xaml - 从 WinRTXamlToolkit 设置 ColumnChart
- vue.js - Vue 路由器如何帮助更快地加载页面?
- java - 在 ArrayList 中对 ArrayList 进行排序
- material-ui - MaterialUI 中的 CSS 过渡
- python - 在插入整数时显示错误
- python - 使用 PRAW 从文本文件中删除注释
- google-api - 使用服务帐户使用 Google Drive API 创建文件不会在授权用户帐户的 GD 上呈现文件
- javascript - Material UI 自动完成,多个默认值
- lua - 尝试在 Lua/Love2D 中绘制平台时出错
- node.js - 执行 npm start 时出现 Azure 函数节点错误