【发布时间】:2019-07-14 07:54:18
【问题描述】:
Spring 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(FluxTake. java:424)","reactor.core.publisher.FluxTake$TakeFuseableSubscriber.onNext(FluxTake.java:404)","reactor.core.publisher.FluxIterable$IterableSubscription.fastPath(FluxIterable.java:311)","reactor .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!
【问题讨论】:
标签: java spring-boot cassandra pagination spring-data-cassandra