【发布时间】:2018-11-23 13:19:05
【问题描述】:
当我尝试从 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"/>
我在 google 上进行了大量搜索,并在 StackOverflow 上检查了相同的问题并且很累,但我仍然坚持同样的问题
【问题讨论】:
-
我怀疑错误是您的电子邮件地址字段在 Solr 中也是多值的,但是您将其定义为字符串,因此在日志中它抱怨由于数据类型不匹配而无法绑定
-
引起:org.apache.solr.client.solrj.beans.BindingException:设置值时出现异常:私有 java.lang.String com.kaldin.dto 上的 [pleaseverify@email.com]。 LeadDTO.email_address 数组列表到字符串无法映射