gpt4 book ai didi

java - org.apache.solr.client.solrj.beans.BindingException : Exception while setting value

转载 作者:行者123 更新时间:2023-11-30 05:54:20 27 4
gpt4 key购买 nike

当我尝试从 Solr 获取 DTO 类型列表中的结果时,出现上述错误。

我有下面的bean类

@Field("email_address")
private String email_address;

@Field("bean_module")
private String bean_module;

@Field("previous_status")
private List<String> previous_status;

我尝试使用以下代码从 Solr 获取结果:

SolrQuery params = new SolrQuery();
QueryResponse response = SOLRCORE.query(params);
SolrDocumentList productDocumentList = response.getResults();
DocumentObjectBinder binder = new DocumentObjectBinder();
List<LeadDTO> arrayList = binder.getBeans(LeadDTO.class,productDocumentList);

上面的代码抛出下面的异常。

org.apache.solr.client.solrj.beans.BindingException: Could not instantiate object of class com.kaldin.dto.LeadDTO
at org.apache.solr.client.solrj.beans.DocumentObjectBinder.getBean(DocumentObjectBinder.java:71)
at org.apache.solr.client.solrj.beans.DocumentObjectBinder.getBeans(DocumentObjectBinder.java:50)
at org.apache.solr.client.solrj.response.QueryResponse.getBeans(QueryResponse.java:618)
at com.kaldin.dao.SolarDao.getSearchResult(SolarDao.java:193)
at com.kaldin.dao.SolarDao.main(SolarDao.java:452)
Caused by: org.apache.solr.client.solrj.beans.BindingException: Exception while setting value : [pleaseverify@email.com] on private java.lang.String com.kaldin.dto.LeadDTO.email_address
at org.apache.solr.client.solrj.beans.DocumentObjectBinder$DocField.set(DocumentObjectBinder.java:455)
at org.apache.solr.client.solrj.beans.DocumentObjectBinder$DocField.inject(DocumentObjectBinder.java:438)
at org.apache.solr.client.solrj.beans.DocumentObjectBinder.getBean(DocumentObjectBinder.java:67)
... 4 more
Caused by: java.lang.IllegalArgumentException: Can not set java.lang.String field com.kaldin.dto.LeadDTO.email_address to java.util.ArrayList
at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:167)
at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:171)
at sun.reflect.UnsafeObjectFieldAccessorImpl.set(UnsafeObjectFieldAccessorImpl.java:81)
at java.lang.reflect.Field.set(Field.java:764)
at org.apache.solr.client.solrj.beans.DocumentObjectBinder$DocField.set(DocumentObjectBinder.java:449)

下面是我们在 Solr 中添加的字段

<field name="email_address" type="text_general" indexed="true" stored="true"/>
<field name="bean_module" type="text_general" indexed="true" stored="true"/>
<field name="previous_status" type="text_general" multiValued="true" indexed="true" stored="true"/>

我在谷歌上进行了大量搜索,并在 StackOverflow 上检查了相同的问题,但我仍然坚持同样的问题

最佳答案

我也面临着同样的异常。我添加了 multiValued = "false" 并且它对我有用。正如日志所示, ArrayList 将被分配给 String,这是不可能的。

Caused by: org.apache.solr.client.solrj.beans.BindingException: Exception while setting value : [pleaseverify@email.com] on private java.lang.String

DTO 中的

email_address 是字符串

@Field("email_address")
private String email_address;

我希望当您像这样使用 multiValued="false" 时它会起作用。

<field name="email_address" type="text_general" indexed="true" stored="true" multiValued="false"/>

关于java - org.apache.solr.client.solrj.beans.BindingException : Exception while setting value,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53447476/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com