I'm playing with Spring Boot 2 with webflux
. I'm trying to use ReactiveSortingRepository
to simplify redis ops.
public interface DataProfileRepository extends ReactiveSortingRepository<DataProfileDTO, String> {
}
Simply use this interface
Mono<DataProfileDTO> tmp = this.dataProfileRepository.findById(id);
exception:
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]
is thrown.
The behavior of this repository didn't match reactor, I can see in the debug mode, an actual DataProfileDTO
was fetched from redis. And failed when trying to:
GENERIC_CONVERSION_SERVICE.convert(reactiveObject, targetWrapperType);
in ReactiveWrapperConverters.toWrapper
I went googling, it seems Spring Data Redis 2.0 doesn't mention reactive repository support. I'm wondering if anything I did wrong in my code or Spring Data Redis 2.0 just doesn't support ReactiveCrudRepository yet.
After adding the Redis dependencies, you now need to perform some configuration so that it could be used in your project. Spring Boot will automatically configure a Redis-cache Manager but with default properties. We can modify this configuration and change it as per our requirement.
Reactive Redis Template Spring Data Redis provides a Reactive API which plays well with all the other reactive parts of the Spring framework.
Spring Data Redis, part of the larger Spring Data family, provides easy configuration and access to Redis from Spring applications. It offers both low-level and high-level abstractions for interacting with the store, freeing the user from infrastructural concerns.
According to Spring's documentation for Reactive Redis Support, the highest level of abstraction to interface with Redis with reactive support is ReactiveRedisTemplate
. The ReactiveRedisConnection
is lower abstraction that works with binary values (ByteBuffer) as input and output.
There's no mention of support of reactive repositories. You can also consult the official reactive examples in the spring-data github repo.
In order for all this to work, you need to have reactive support in the driver you're using - currently that would be lettuce.
Although not ideal, an alternative is Flux.fromIterable()
. You can use blocking repository and handle the result in reactive way.
public interface DataProfileRepository extends CrudRepository<DataProfileDTO, String> {
}
And wrap it:
Flux.fromIterable(dataProfileRepository.findById(id)), DataProfileDTO.class))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With