我扩展了 MongoRepository 并想使用 Stream API。根据引用,我声明了一个查询方法:
public Stream<MyType> findByIdIn(Iterable<? extends String> myTypeIds);
但是,当启动我的 Spring Boot 应用程序时,会抛出 PropertyNotFoundException
并指出:
No property id found for type Stream!
我的域类型派生自包含 MongoDB 对象实际 ID 的父类(super class)型。有什么想法可以解决这个问题吗?
我正在使用 Spring Boot 1.2.0.RELEASE 和 Spring Data MongoDB 1.6.1.RELEASE。
最佳答案
Spring Data MongoDB 版本 1.7 中添加了对 Stream
作为返回类型的支持,as per the release notes :
What’s new in Spring Data MongoDB 1.7
...
- Allow
Stream
as query method return type
因此,您需要从 1.6.1.RELEASE 至少更新到版本 1.7。如果您使用Maven,则可以为当前最新版本(1.8.2.RELEASE)添加以下依赖项:
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb</artifactId>
<version>1.8.2.RELEASE</version>
</dependency>
关于java - 尝试将 spring data mongo 存储库与 Stream 一起使用时出现异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35320322/