首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >org.ektorp.InvalidDocumentException:无法解析类中的id访问器

org.ektorp.InvalidDocumentException:无法解析类中的id访问器
EN

Stack Overflow用户
提问于 2020-01-09 03:53:20
回答 1查看 118关注 0票数 0

我正在编写一个在CouchDB上插入数据的java应用程序。为此,我使用了Ektorp,并获得了异常org.ektorp.InvalidDocumentException: Cannot resolve id accessor in class

下面是我的maven依赖项:

代码语言:javascript
复制
<dependency>
  <groupId>org.ektorp</groupId>
  <artifactId>org.ektorp</artifactId>
  <version>1.4.4</version>
</dependency>

<dependency>
  <groupId>com.fasterxml.jackson.core</groupId>
  <artifactId>jackson-annotations</artifactId>
  <version>2.9.10</version>
</dependency>

POJO,如here所述

代码语言:javascript
复制
public class Item {

    @JsonProperty("_index")
    public String index;

    @JsonProperty("_type")
    public String type;

    @JsonProperty("_id")
    public String id;

    @JsonProperty("_score")
    public float score;

}

存储库:

代码语言:javascript
复制
public class ItemRepository extends CouchDbRepositorySupport<Item> {
    public ItemRepository(CouchDbConnector db) {
        super(Item.class, db);
    }
}

以及我试图添加的内容:

代码语言:javascript
复制
Item x = new Item();
x.id = "1291";
x.index="test_index";
x.score = 1;
x.type = "_doc";

this.repo = new ItemRepository(this.db);
this.repo.add(x);

错误描述:

代码语言:javascript
复制
Exception in thread "main" org.ektorp.InvalidDocumentException: Cannot resolve id accessor in class org.example.Item
    at org.ektorp.util.Documents$MethodAccessor.assertMethodFound(Documents.java:165)
    at org.ektorp.util.Documents$MethodAccessor.<init>(Documents.java:136)
    at org.ektorp.util.Documents.getAccessor(Documents.java:113)
    at org.ektorp.util.Documents.getRevision(Documents.java:77)
    at org.ektorp.util.Documents.isNew(Documents.java:85)
    at org.ektorp.support.CouchDbRepositorySupport.add(CouchDbRepositorySupport.java:100)
    at org.example.DataBase.addItem(DataBase.java:69)
    at org.example.App.main(App.java:42)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)

我不确定我做错了什么。我不确定我是否使用了正确的JSON库,因为他们在文档中的链接已经不存在了。

感谢您的帮助

EN

回答 1

Stack Overflow用户

发布于 2020-01-09 04:00:04

我解决了这个问题。这只是一个放置正确依赖项的问题。这个id就是正确的:

代码语言:javascript
复制
  <dependency>
      <groupId>org.codehaus.jackson</groupId>
      <artifactId>jackson-core-lgpl</artifactId>
      <version>1.9.13</version>
  </dependency>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59652946

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档