当我尝试从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上检查了相同的问题,很累,但我仍然遇到相同的问题
答案 0 :(得分:0)
我面临着同样的例外。我添加了multiValued = "false"
,它对我有用。日志显示ArrayList
将被分配给String
,这是不可能的。
DTO中的由以下原因引起:org.apache.solr.client.solrj.beans.BindingException:在私有java.lang.String上设置值[pleaseverify@email.com]时发生异常
和email_address
是字符串
@Field("email_address")
private String email_address;
我希望当您像这样使用multiValued="false"
时,它会起作用。
<field name="email_address" type="text_general" indexed="true" stored="true" multiValued="false"/>