春季cassandra数据使获取分页信息变得容易。 但是我无法使它正常工作。
回购,致电和错误:
1。反应性通话
回购:
public interface MyRepository extends ReactiveCassandraRepository<MyClass, String> {
@Query("select * from my_keyspace.my_table where solr_query = ?0")
Mono<Slice<MyClass>> findMono(String solrQuery, Pageable page);
}
致电:
Mono<Slice<MyClass>> repository.findMono(queryString, CassandraPageRequest.first(20));
错误:
“ exceptionDescription”:“ org.springframework.core.codec.CodecException: 类型定义错误:[简单类型,类 com.datastax.driver.core.PagingState];嵌套异常为 com.fasterxml.jackson.databind.exc.InvalidDefinitionException:否 找到类com.datastax.driver.core.PagingState的序列化器,并且没有 发现的用于创建BeanSerializer的属性(为避免出现异常, 禁用SerializationFeature.FAIL_ON_EMPTY_BEANS)(通过引用 链: org.springframework.data.domain.SliceImpl [\“ pageable \”]-> org.springframework.data.cassandra.core.query.CassandraPageRequest [\“ pagingState \”])“,” lines“:[” org.springframework .http.codec.json.AbstractJackson2Encoder.encodeValue(AbstractJackson2Encoder.java:175)“,” org.springframework.http.codec.json.AbstractJackson2Encoder.lambda $ encode $ 0(AbstractJackson2Encoder.java:122)“,” reactor.core。 Publisher.FluxMap $ MapSubscriber.onNext(FluxMap.java:100)“,” reactor.core.publisher.FluxSwitchIfEmpty $ SwitchIfEmptySubscriber.onNext(FluxSwitchIfEmpty.java:67)“,” reactor.core.publisher.FluxMap $ MapSubscriber.onNext( FluxMap.java:114)","reactor.core.publisher.FluxDefaultIfEmpty$DefaultIfEmptySubscriber.onNext(FluxDefaultIfEmpty.java:92)","reactor.core.publisher.Operators$MonoSubscriber.complete(Operators.java:1476)“, “” reactor.core.publisher.MonoFlatMap $ FlatMapInner.onNext(MonoFlatMap.java:241)“,” reactor.core.publisher.FluxMapFuseable $ MapFuseableSubscriber.onNext(FluxMapFuseable.java:121)“,” reactor.core.publisher。 Operators $ MonoSubscriber.complete(Operators.java:1476)“,” reactor.core.publisher.MonoCollectList $ MonoBufferAllSubscriber.onComplete(MonoCollectList.java:118)“,” reactor.core.publisher.FluxTake $ TakeFuseableSubscriber.onComplete(luxT java:424)“,” reactor.core.publisher.FluxTake $ TakeFuseableSubscriber.onNext(FluxTake.java:404)“,” reactor.core.publisher.FluxIterable $ IterableSubscription.fastPath(FluxIterable.java:311)“,”反应器.core.publisher.FluxIterable $ IterableSubscription.request(FluxIterable.java:198)“],
2。通过ReactiveSortingRepository进行反应
回购:
public interface LocationRepository extends ReactiveSortingRepository<MyClass, String> {
}
致电:
repository.findAll(CassandraPageRequest.first(20))
错误:
语法错误:findAll不能应用于CassandraPageRequest。
3。只需调用即可获取页面。
回购:
public interface MyRepository extends CassandraRepository<MyClass, MyClassKey> {
Page<MyClass> findByKeyTerminalIdAndSolrQuery(String solrQuery, Pageable page);
}
启动时出错:
原因:org.springframework.dao.InvalidDataAccessApiUsageException: 不支持页面查询。使用切片查询。
4。使用PagingAndSortingRepository
回购:
public interface MyRepository extends PagingAndSortingRepository<MyClass, MyClassKey> {
}
致电:
Page<Vessel> vessels = repository.findAll(CassandraPageRequest.first(10));
错误:
springframework.data.mapping.PropertyReferenceException:无属性 发现所有类型为MyClass的findAll!
答案 0 :(得分:1)
欢迎使用堆栈溢出。
第一个示例是合适的示例:
public interface MyRepository extends ReactiveCassandraRepository<MyClass, String> {
@Query("select * from my_keyspace.my_table where solr_query = ?0")
Mono<Slice<MyClass>> findMono(String solrQuery, Pageable page);
}
Mono<Slice<MyClass>> repository.findMono(queryString, CassandraPageRequest.first(20));
问题在于,杰克逊无法在将SliceImpl
(Slice
的实现)传递给WebFlux时对其进行编码(根据堆栈跟踪)。因此,查询会产生正确的结果,但是如果要对其进行JSON编码,则需要传递Slice
内容,而不是Slice
本身。
相关说明:ReactiveCassandraRepository
未实现ReactiveSortingRepository
,因为带有Sort
自变量的Casandra查询始终需要一个WHERE
子句。查看ReactiveSortingRepository
,您会看到一种findAll(Sort)
方法没有采用过滤条件:
public interface ReactiveSortingRepository<T, ID> extends ReactiveCrudRepository<T, ID> {
Flux<T> findAll(Sort sort);
}