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, ...
随机推荐
- LG5104 红包发红包 概率与期望
问题描述 LG5104 题解 观察发现,对于 \(w\) ,期望得钱是 \(\frac{w}{2}\) . 然后答案就是 \(\frac{w}{2^k}\) . 然后快速幂求个逆元就好了. \(\ma ...
- SQL Server 创建 修改 删除数据表
1. 图形界面方式操作数据表 (1)创建和修改数据表 列名中如果有两个以上单词时,最好用下划线连接,否则可能会给将来的查询维护带来不便.我们公司美国佬做的数据库就很烦,所有列名都有空格,一旦忘记用方括 ...
- JVM垃圾回收GC
1.堆的分代和区域 (年轻代)Young Generation(eden.s0.s1 space) Minor GC (老年代)Old Generation (Tenured space) ...
- vue 多种方式控制style属性
一共用到了两种方式: 第一种:对象 第二种:数组 看代码: <!doctype html> <html lang="en"> <head> &l ...
- 项目倒入maven 遇到的问题只有 main 了
归根结底是倒入错了: (1)首先 view->Toolbar; (2) 点击 File==>project structure 然后:在 project settings中点击 modu ...
- mac pe简单安装方法
1.工具下载 TechTool Pro for mac V11.0.4:http://www.pc6.com/mac/112462.html 2.准备16g u盘 3.安装工具并按照注册码注册 在Te ...
- Oracle SQL调优之表设计
在看<收获,不止sql优化>一书,并做了笔记,本博客介绍一下一些和调优相关的表比如分区表.临时表.索引组织表.簇表以及表压缩技术 分区表使用与查询频繁而更新数据不频繁的情况,不过要记得加全 ...
- RSyslog Windows Agent 安装配置
下载地址:https://www.rsyslog.com/windows-agent/windows-agent-download/ 安装过程: 1.双击rsyslogwa安装包,开始进行安装 2.一 ...
- 调用SqlCommand或SqlDataAdapter的Dispose方法,是否会关闭绑定的SqlConnection?(转载)
1. Does SqlCommand.Dispose close the connection? 问 Can I use this approach efficiently? using(SqlCom ...
- C# NPOI Export DataTable C# NPOI导出DataTable 单元格自适应大小
1.Install-Package NPOI -v 2.4.0 2. using NPOI.XSSF; using NPOI.XSSF.UserModel; using NPOI.SS.UserMod ...