将 Spring 数据的 ReactiveCrudRepository 应用到 Redis
Apply Spring Data's ReactiveCrudRepository to Redis
我正在玩 Spring Boot 2 和 webflux
。我正在尝试使用 ReactiveSortingRepository
来简化 redis 操作。
public interface DataProfileRepository extends ReactiveSortingRepository<DataProfileDTO, String> {
}
就用这个接口
Mono<DataProfileDTO> tmp = this.dataProfileRepository.findById(id);
异常:
org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [com.tradeshift.dgps.dto.DataProfileDTO] to type [reactor.core.publisher.Mono<?>]
at org.springframework.core.convert.support.GenericConversionService.handleConverterNotFound(GenericConversionService.java:321) ~[spring-core-5.0.2.RELEASE.jar:5.0.2.RELEASE]
at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:194) ~[spring-core-5.0.2.RELEASE.jar:5.0.2.RELEASE]
at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:174) ~[spring-core-5.0.2.RELEASE.jar:5.0.2.RELEASE]
at org.springframework.data.repository.util.ReactiveWrapperConverters.toWrapper(ReactiveWrapperConverters.java:197) ~[spring-data-commons-2.0.2.RELEASE.jar:2.0.2.RELEASE]
at org.springframework.data.repository.core.support.QueryExecutionResultHandler.postProcessInvocationResult(QueryExecutionResultHandler.java:104) ~[spring-data-commons-2.0.2.RELEASE.jar:2.0.2.RELEASE]
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:587) ~[spring-data-commons-2.0.2.RELEASE.jar:2.0.2.RELEASE]
被抛出。
这个存储库的行为与 reactor 不匹配,我可以在调试模式下看到,实际的 DataProfileDTO
是从 redis 中获取的。尝试时失败:
GENERIC_CONVERSION_SERVICE.convert(reactiveObject, targetWrapperType);
在ReactiveWrapperConverters.toWrapper
我去谷歌搜索,似乎 Spring Data Redis 2.0 没有提到响应式存储库支持。我想知道我的代码是否有任何错误,或者 Spring Data Redis 2.0 还不支持 ReactiveCrudRepository。
根据 Spring 的文档,Reactive Redis Support, the highest level of abstraction to interface with Redis with reactive support is ReactiveRedisTemplate
. The ReactiveRedisConnection
是使用二进制值 (ByteBuffer) 作为输入和输出的较低抽象。
没有提到对响应式存储库的支持。
也可以参考spring-data github repo.
中的官方响应式示例
为了使所有这些工作正常,您需要在您使用的驱动程序中提供响应式支持 - 目前是 lettuce。
虽然不理想,但替代方案是 Flux.fromIterable()
。您可以使用阻塞存储库并以反应方式处理结果。
public interface DataProfileRepository extends CrudRepository<DataProfileDTO, String> {
}
并包装它:
Flux.fromIterable(dataProfileRepository.findById(id)), DataProfileDTO.class))
我正在玩 Spring Boot 2 和 webflux
。我正在尝试使用 ReactiveSortingRepository
来简化 redis 操作。
public interface DataProfileRepository extends ReactiveSortingRepository<DataProfileDTO, String> {
}
就用这个接口
Mono<DataProfileDTO> tmp = this.dataProfileRepository.findById(id);
异常:
org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [com.tradeshift.dgps.dto.DataProfileDTO] to type [reactor.core.publisher.Mono<?>]
at org.springframework.core.convert.support.GenericConversionService.handleConverterNotFound(GenericConversionService.java:321) ~[spring-core-5.0.2.RELEASE.jar:5.0.2.RELEASE]
at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:194) ~[spring-core-5.0.2.RELEASE.jar:5.0.2.RELEASE]
at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:174) ~[spring-core-5.0.2.RELEASE.jar:5.0.2.RELEASE]
at org.springframework.data.repository.util.ReactiveWrapperConverters.toWrapper(ReactiveWrapperConverters.java:197) ~[spring-data-commons-2.0.2.RELEASE.jar:2.0.2.RELEASE]
at org.springframework.data.repository.core.support.QueryExecutionResultHandler.postProcessInvocationResult(QueryExecutionResultHandler.java:104) ~[spring-data-commons-2.0.2.RELEASE.jar:2.0.2.RELEASE]
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:587) ~[spring-data-commons-2.0.2.RELEASE.jar:2.0.2.RELEASE]
被抛出。
这个存储库的行为与 reactor 不匹配,我可以在调试模式下看到,实际的 DataProfileDTO
是从 redis 中获取的。尝试时失败:
GENERIC_CONVERSION_SERVICE.convert(reactiveObject, targetWrapperType);
在ReactiveWrapperConverters.toWrapper
我去谷歌搜索,似乎 Spring Data Redis 2.0 没有提到响应式存储库支持。我想知道我的代码是否有任何错误,或者 Spring Data Redis 2.0 还不支持 ReactiveCrudRepository。
根据 Spring 的文档,Reactive Redis Support, the highest level of abstraction to interface with Redis with reactive support is ReactiveRedisTemplate
. The ReactiveRedisConnection
是使用二进制值 (ByteBuffer) 作为输入和输出的较低抽象。
没有提到对响应式存储库的支持。 也可以参考spring-data github repo.
中的官方响应式示例为了使所有这些工作正常,您需要在您使用的驱动程序中提供响应式支持 - 目前是 lettuce。
虽然不理想,但替代方案是 Flux.fromIterable()
。您可以使用阻塞存储库并以反应方式处理结果。
public interface DataProfileRepository extends CrudRepository<DataProfileDTO, String> {
}
并包装它:
Flux.fromIterable(dataProfileRepository.findById(id)), DataProfileDTO.class))