尝试将 Spring Data mongo 存储库与 Stream 一起使用时出现异常 [英] Exception when trying to use spring data mongo repository with Stream

查看:25
本文介绍了尝试将 Spring Data mongo 存储库与 Stream 一起使用时出现异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我扩展了 MongoRepository 并想使用 Stream API.根据参考,我声明了一个查询方法:

public StreamfindByIdIn(Iterable myTypeIds);

但是,在启动我的 Spring Boot 应用程序时,会抛出一个 PropertyNotFoundException 说明:

<块引用>

未找到类型 Stream 的属性 ID!

我的域类型源自包含 MongoDB 对象的实际 id 的超类型.任何想法如何解决这个问题?

我使用的是 Spring Boot 1.2.0.RELEASE 和 Spring Data MongoDB 1.6.1.RELEASE.

解决方案

在 Spring Data MongoDB 1.7 版中添加了对 Stream 作为返回类型的支持,根据发行说明:><块引用>

Spring Data MongoDB 1.7 的新变化

...

  • 允许 Stream 作为查询方法返回类型

因此,您需要从 1.6.1.RELEASE 更新到至少 1.7 版本.如果您使用的是 Maven,则可以为当前最新版本 1.8.2.RELEASE 添加以下依赖项:

<groupId>org.springframework.data</groupId><artifactId>spring-data-mongodb</artifactId><version>1.8.2.RELEASE</version></依赖>

I have MongoRepository extended and want to use the Stream API. As by the reference, I declared a query method:

public Stream<MyType> findByIdIn(Iterable<? extends String> myTypeIds);

However, when starting up my Spring Boot application, a PropertyNotFoundExceptionis thrown stating:

No property id found for type Stream!

My domain type derives from a supertype containing the actual id of the MongoDB object. Any ideas how to fix this?

I am using Spring Boot 1.2.0.RELEASE and Spring Data MongoDB 1.6.1.RELEASE.

解决方案

Support for Stream as a return-type was added in Spring Data MongoDB version 1.7, as per the release notes:

What’s new in Spring Data MongoDB 1.7

...

  • Allow Stream as query method return type

Therefore, you need to update from 1.6.1.RELEASE to at least version 1.7. If you are using Maven, you could add the following dependency for the current latest version, which is 1.8.2.RELEASE:

<dependency>
    <groupId>org.springframework.data</groupId>
    <artifactId>spring-data-mongodb</artifactId>
    <version>1.8.2.RELEASE</version>
</dependency>

这篇关于尝试将 Spring Data mongo 存储库与 Stream 一起使用时出现异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆