solr.UncategorizedSolrException: Can't resolve required map value type for interface java.util.Map!

2019-03-09 09:39:12.006 ERROR 1564 --- [nio-9104-exec-2] o.a.c.c.C.[.[.[.[dispatcherServlet]      : Servlet.service() for servlet [dispatcherServlet] in context with path [/search] threw exception [Request processing failed; nested exception is java.lang.reflect.UndeclaredThrowableException] with root cause

java.lang.RuntimeException: org.springframework.data.solr.UncategorizedSolrException: Can't resolve required map value type for interface java.util.Map!; nested exception is java.lang.IllegalStateException: Can't resolve required map value type for interface java.util.Map!
org.springframework.data.solr.UncategorizedSolrException: Can't resolve required map value type for interface java.util.Map!; nested exception is java.lang.IllegalStateException: Can't resolve required map value type for interface java.util.Map!
	at org.springframework.data.solr.core.SolrTemplate.execute(SolrTemplate.java:171)
	at org.springframework.data.solr.core.SolrTemplate.saveBeans(SolrTemplate.java:227)
	at org.springframework.data.solr.core.SolrOperations.saveBeans(SolrOperations.java:160)
	...
	at java.lang.Thread.run(Thread.java:748)

在这里插入图片描述
应该改成
在这里插入图片描述
同理,在json解析的时候也要注意接口与实现类的使用。
在这里插入图片描述

总结:

  • 在json解析的时候,java会利用反射创建对象,解析json赋值,因此不要使用Map.class,要使用HashMap.class。
HashMap specMap = JSON.parseObject(item.getSpec(),HashMap.class);
  • 在实体类中的对象,若要作为返回值,应注意接口与实现类的使用,比如solr,不能解析Map接口。因为要创建对象。
Can't resolve required map value type for interface java.util.Map!
  • 在mybatis中的返回值,也不要写List或Map的接口,要使用ArrayList,HashMap实现类。
  • 接口不能实例化!!!!
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值