Spring Data Solr创建动态域报错:org.springframework.data.solr.UncategorizedSolrException
今天在项目中使用Spring Data Solr导入动态域数据报错, 控制台打印错误信息如下
Exception in thread "main" org.springframework.data.solr.UncategorizedSolrException: nested exception is java.lang.NullPointerException at org.springframework.data.solr.core.SolrTemplate.execute(SolrTemplate.java:145) at org.springframework.data.solr.core.SolrTemplate.saveBeans(SolrTemplate.java:199) at org.springframework.data.solr.core.SolrTemplate.saveBeans(SolrTemplate.java:194) at com.pinyougou.solrutil.ImportItem.importAllItem(ImportItem.java:46) at com.pinyougou.solrutil.ImportItem.main(ImportItem.java:53) Caused by: java.lang.NullPointerException at org.springframework.data.solr.core.convert.MappingSolrConverter.writeWildcardMapPropertyToTarget(MappingSolrConverter.java:310) at org.springframework.data.solr.core.convert.MappingSolrConverter.access$100(MappingSolrConverter.java:62) at org.springframework.data.solr.core.convert.MappingSolrConverter$2.doWithPersistentProperty(MappingSolrConverter.java:287) at org.springframework.data.solr.core.convert.MappingSolrConverter$2.doWithPersistentProperty(MappingSolrConverter.java:269) at org.springframework.data.mapping.model.BasicPersistentEntity.doWithProperties(BasicPersistentEntity.java:311) at org.springframework.data.solr.core.convert.MappingSolrConverter.write(MappingSolrConverter.java:269) at org.springframework.data.solr.core.convert.MappingSolrConverter.write(MappingSolrConverter.java:258) at org.springframework.data.solr.core.convert.MappingSolrConverter.write(MappingSolrConverter.java:62) at org.springframework.data.solr.core.SolrTemplate.convertBeanToSolrInputDocument(SolrTemplate.java:463) at org.springframework.data.solr.core.SolrTemplate.convertBeansToSolrInputDocuments(SolrTemplate.java:546) at org.springframework.data.solr.core.SolrTemplate.access$100(SolrTemplate.java:91) at org.springframework.data.solr.core.SolrTemplate$5.doInSolr(SolrTemplate.java:202) at org.springframework.data.solr.core.SolrTemplate$5.doInSolr(SolrTemplate.java:199) at org.springframework.data.solr.core.SolrTemplate.execute(SolrTemplate.java:141)
public class TbItem implements Serializable { @Field private Long id; //其他属性略 @Dynamic //动态域 @Field("item_spec_*") private Map specMap; //set() get()略 !
@Component("importItem") public class ImportItem { @Autowired private SolrTemplate solrTemplate; @Autowired private TbItemMapper itemMapper; private void importAllItem(){ TbItemExample example = new TbItemExample(); TbItemExample.Criteria criteria = example.createCriteria(); criteria.andStatusEqualTo("1");//只查询状态为 1 的数据 List<TbItem> list = itemMapper.selectByExample(example); for (TbItem item : list) { /* spec是POJO中另外的属性 item.getSpec() 得到数据结构: {"网络":"移动4G","机身内存":"32G"} 使用fastjson 转换为Map,存放在POJO中 */ Map specMap = JSON.parseObject(item.getSpec(), Map.class); item.setSpecMap(specMap); } /* *统一保存 */ solrTemplate.saveBeans(list); solrTemplate.commit(); } public static void main(String[] args) { ApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath*:spring/applicationContext*.xml"); ImportItem util = (ImportItem) applicationContext.getBean("importItem"); util.importAllItem(); } }
在网上没有找到对应的解决方案,不断尝试,将POJO中Map的范型加上后结果OK!!!
@Dynamic //动态域 @Field("item_spec_*") private Map<String,String> specMap;//最好将范型加上 //set() get()略
因为是Maven分模块开发,将POJO重新install就可以了
2019-07-1510:47:32
作者:深海收破烂
Spring Data Solr创建动态域报错:org.springframework.data.solr.UncategorizedSolrException的更多相关文章
- 【spring boot】【elasticsearch】spring boot整合elasticsearch,启动报错Caused by: java.lang.IllegalStateException: availableProcessors is already set to [8], rejecting [8
spring boot整合elasticsearch, 启动报错: Caused by: java.lang.IllegalStateException: availableProcessors ], ...
- eclipse 向HDFS中创建文件夹报错 permission denied
环境:win7 eclipse hadoop 1.1.2 当执行创建文件的的时候, 即: String Path = "hdfs://host2:9000"; FileSy ...
- Redis创建集群报错
Redis创建集群报错: 1:任何一个集群节点中都不能存在数据,如果有备份一下删除掉aof文件或rdb文件 2: nodes-集群端口.conf 文件存的会有报错记录,所以该文件也要删除
- Mysql表创建外键报错
数据库表A: CREATE TABLE task_desc_tab ( id INT(11) PRIMARY KEY NOT NULL COMMENT '自增主键' AUTO_INCREMENT, t ...
- 报错:System.Data.Entity.Validation.DbEntityValidationException: 对一个或多个实体的验证失败
使用MVC和EF,在保存数据的时候报错:System.Data.Entity.Validation.DbEntityValidationException: 对一个或多个实体的验证失败.有关详细信息, ...
- 【spring boot】spring cloud下spring boot微服务启动没有报错,但是访问访问不到
spring cloud下spring boot微服务启动没有报错,但是访问访问不到 解决方法: 可能是端口被占用了,但是依旧启用成功了. 更改一下项目启用的端口号,再重新启动查看是否可以正常访问.
- Bug集锦-Spring Cloud Feign调用其它接口报错
问题描述 Spring Cloud Feign调用其它服务报错,错误提示如下:Failed to instantiate [java.util.List]: Specified class is an ...
- canvas.toDataURL 由于跨域报错的解决方法
关于canvas.toDataURL 由于跨域报错的解决方法 用过canvas,都知道toDataURL这个方法真好用,不仅合成图片用到它,压缩图片也用到它.但有一个问题,就是图片源不能跨域,不然会报 ...
- 完美解决 scipy.misc.imread 报错 TypeError: Image data cannot be converted to float
File "/home/harrison/anaconda3/lib/python3.7/site-packages/matplotlib/image.py", line 634, ...
随机推荐
- [C7] Andrew Ng - Sequence Models
About this Course This course will teach you how to build models for natural language, audio, and ot ...
- BZOJ2733/LG3324 「HNOI2014」永无乡 权值线段树合并
问题描述 BZOJ2733 LG3224 题解 对于每个结点建立一棵权值线段树. 查询操作就去查询第 \(k\) 大,合并操作就合并两颗权值线段树. 并查集维护连通性. 同时 STO hkk,zcr, ...
- luoguP4248 [AHOI2013]差异
题意 考虑式子前面那段其实是\((n-1)*\frac{n*(n+1)}{2}\),因为每个后缀出现了\(n-1\)次,后缀总长为\(\frac{n*(n+1)}{2}\). 现在考虑后面怎么求: \ ...
- git操作记录(如何回退到某个历史版本,如何提交部分文件等方法)
当前项目使用git管理代码,在使用的过程中会遇到一些问题,这里记录下 1.合并代码后 在合并组员的代码后会出现下面的界面,开始的时候都会关闭,重新打开,乐此不疲到忍无可忍 解决方法: 出现这种界面是要 ...
- 简述vue props和非props的2个特性
props的2个特性 ①:父组件通过属性的方式传值(比如下面截图中的content)给子组件,content不会显示在DOM节点中 ②:父组件向子组件传递值 ...
- Vue.js 源码分析(三十) 高级应用 函数式组件 详解
函数式组件比较特殊,也非常的灵活,它可以根据传入该组件的内容动态的渲染成任意想要的节点,在一些比较复杂的高级组件里用到,比如Vue-router里的<router-view>组件就是一个函 ...
- Python 多进程池
def get_html(n): time.sleep(n) print("sub_progress success") return n # 多进程池 pool = multip ...
- win10每次开机都会自检系统盘(非硬件故障)——解决方案2019.07.12
1.最近反复遇到了这个问题,之前遇到这个问题就把系统重装了,没想到今天又遇到了,目前系统东西太多了,重装太麻烦了,就下决心解决一下. 2.不要使用网络上流传的修改注册表的方案,把注册表的那个键值删除那 ...
- 关于 BenchmarkDotNet
using BenchmarkDotNet.Attributes; using BenchmarkDotNet.Order; using System.Reflection; namespace Be ...
- springboot只能一个main方法解决办法
pom.xml修改properties,增加这行 <start-class>com.eshore.main.SpringBootStarter</start-class> 或者 ...