Spring Data Couchbase索引问题

时间:2018-08-25 22:49:57

标签: spring-boot couchbase spring-data-couchbase

我正在使用榻榻米和弹簧数据榻榻米。为此,我安装了版本为5.5.1 build 3511的沙发床,并启用了测试桶。我已经用密码beer-sample创建了用户beer-sample,并向他添加了存储桶beer-sample的所有特权。

然后,我创建了this sample application,并配置了沙发床。当我启动该应用程序并为存储桶中的现有啤酒query启动时,出现异常:

com.couchbase.client.java.error.ViewDoesNotExistException: View beer/all does not exist.
    at com.couchbase.client.java.view.ViewQueryResponseMapper$BuildViewResult.call(ViewQueryResponseMapper.java:211)
    at com.couchbase.client.java.view.ViewQueryResponseMapper$BuildViewResult.call(ViewQueryResponseMapper.java:185)
    at rx.internal.operators.OnSubscribeMap$MapSubscriber.onNext(OnSubscribeMap.java:69)
    at rx.internal.operators.OnSubscribeMap$MapSubscriber.onNext(OnSubscribeMap.java:77)
    at rx.internal.producers.SingleProducer.request(SingleProducer.java:65)
    at rx.Subscriber.setProducer(Subscriber.java:211)
    at rx.internal.operators.OnSubscribeMap$MapSubscriber.setProducer(OnSubscribeMap.java:102)
    at rx.internal.operators.OnSubscribeMap$MapSubscriber.setProducer(OnSubscribeMap.java:102)
    at rx.internal.operators.OperatorSingle$ParentSubscriber.onCompleted(OperatorSingle.java:113)
    at rx.internal.operators.OperatorObserveOn$ObserveOnSubscriber.checkTerminated(OperatorObserveOn.java:281)
    at rx.internal.operators.OperatorObserveOn$ObserveOnSubscriber.call(OperatorObserveOn.java:216)
    at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:55)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
Caused by: rx.exceptions.OnErrorThrowable$OnNextValue: OnError while emitting onNext value: com.couchbase.client.java.document.json.JsonObject.class
    at rx.exceptions.OnErrorThrowable.addValueAsLastCause(OnErrorThrowable.java:118)
    at rx.internal.operators.OnSubscribeMap$MapSubscriber.onNext(OnSubscribeMap.java:73)
    ... 16 more

我猜应该使用配置自动创建索引,但是也许我错了。

1 个答案:

答案 0 :(得分:4)

您正在BeerRepository中使用Spring的benchbase存储库界面。接口的findAll()方法希望使用Couchbase View来获取数据。因此,您需要在Couchbase中手动创建视图,或者可以用BeerRepository注释@ViewIndexed(designDoc = "beer", viewName = "all")界面,如果界面不存在,则会自动创建视图。

您所做的错误是用Beer注释了@ViewIndexed类,因为该注释应该用于您的Repository接口。有关注释here的更多信息。

所有这些,您还应该检查如何利用Couchbase的N1QL查询从Couchbase访问数据。您可以在存储库方法上使用@Query注解。有关使用@Query批注here的更多信息。