jjzjj

GridFsTemplate

全部标签

spring - 服务单元测试类中的 GridFsTemplate NullPointerException(技术堆栈 : Spring Data/Spring Boot/Micro Service/Mongodb )

我正在开发一个springboot应用程序。服务方法使用在服务中Autowiring的GridFsTemplate将PDF上传到mongodb存储库。此文件上传服务方法通过postman休息客户端按预期工作。但是,当我尝试运行单元测试时;调用相同的服务方法,SpringDataGridFsTemplate未初始化(在MongoDB中,您可以使用GridFS存储二进制文件)。这导致org.springframework.data.mongodb.gridfs.GridFsTemplate.store(...)抛出NullPointerException。拜托,你能帮忙吗,我已经被困在这几

mongodb - 如何在 Spring Boot 中禁用 GridFS MD5 计算?

现在GridFS文件集合的md5属性已经过时,不需要驱动程序来计算它,所以我想禁用它以节省几毫秒......MongoDBJava驱动程序确实在GridFSBucketImpl中提供了一个选项disableMD5,但是因为我使用的是SpringBoot的GridFsTemplate(spring-data-mongodb2.1.2.RELEASE)我没有直接访问它的权限。GridFsTemplate有一个方法getGridFs()返回为当前数据库和存储桶名称配置的GridFSBucket,但不幸的是这个方法是私有(private)的,所以我可以'覆盖它。那么我的选择是什么?我是否必须覆

mongodb - 如何在不使用GridFSTemplate的情况下在spring boot应用程序中上传和检索mongodb中的文件?

我想上传文件并从springboot应用程序中的mongodb中检索它们。但我不想使用GridFSTemplate,因为我的filesize不会大于16MB。我没有选择GridFSTemplate因为链接https://docs.mongodb.com/manual/core/gridfs/#faq-developers-when-to-use-gridfs中没有提到任何要求不符合我的要求。使用Document保存文件并使用MongoTemplate检索它们是一种好方法吗?MyDocument定义看起来像@DocumentpublicclassMyDocument{@Idprivate