今天在项目中使用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的更多相关文章

  1. 【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 ], ...

  2. eclipse 向HDFS中创建文件夹报错 permission denied

    环境:win7  eclipse    hadoop 1.1.2 当执行创建文件的的时候, 即: String Path = "hdfs://host2:9000"; FileSy ...

  3. Redis创建集群报错

    Redis创建集群报错: 1:任何一个集群节点中都不能存在数据,如果有备份一下删除掉aof文件或rdb文件 2: nodes-集群端口.conf 文件存的会有报错记录,所以该文件也要删除

  4. Mysql表创建外键报错

    数据库表A: CREATE TABLE task_desc_tab ( id INT(11) PRIMARY KEY NOT NULL COMMENT '自增主键' AUTO_INCREMENT, t ...

  5. 报错:System.Data.Entity.Validation.DbEntityValidationException: 对一个或多个实体的验证失败

    使用MVC和EF,在保存数据的时候报错:System.Data.Entity.Validation.DbEntityValidationException: 对一个或多个实体的验证失败.有关详细信息, ...

  6. 【spring boot】spring cloud下spring boot微服务启动没有报错,但是访问访问不到

    spring cloud下spring boot微服务启动没有报错,但是访问访问不到 解决方法: 可能是端口被占用了,但是依旧启用成功了. 更改一下项目启用的端口号,再重新启动查看是否可以正常访问.

  7. Bug集锦-Spring Cloud Feign调用其它接口报错

    问题描述 Spring Cloud Feign调用其它服务报错,错误提示如下:Failed to instantiate [java.util.List]: Specified class is an ...

  8. canvas.toDataURL 由于跨域报错的解决方法

    关于canvas.toDataURL 由于跨域报错的解决方法 用过canvas,都知道toDataURL这个方法真好用,不仅合成图片用到它,压缩图片也用到它.但有一个问题,就是图片源不能跨域,不然会报 ...

  9. 完美解决 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, ...

随机推荐

  1. java.net 基本测试

    java.net 基本测试 包 java.net java.net.ssl 类 java.net.URL 测试类 package com.mozq.boot.kuayu01.demo; import ...

  2. 《Vue 进阶系列之响应式原理及实现》

    https://www.bilibili.com/video/av51444410/?p=5 https://github.com/amandakelake/blog/issues/63 https: ...

  3. LG3205/BZOJ1996 「HNOI2010」合唱队 区间DP

    区间DP 区间DP: 显然是一个区间向左右拓展形成的下一个区间,具有包含关系,所以可以使用区间DP. 状态设计: 考虑和关路灯一样设计状态 因为不知道当前这个区间是从哪个区间拓展而来,即不知道这个区间 ...

  4. java程序 cpu占用过高分析

    linux终端下用 top命令看到cpu占用超过100%.之所以超过100%.说明cpu是多核.默认top显示的是cpu加起来的使用率,运行top后按大键盘1看看,可以显示每个cpu的使用率,top里 ...

  5. 【转】win7旗舰版英文版下载(64位|32位)|Windows7英文版ISO镜像

    Win7旗舰版SP1 64位ISO镜像下载地址:文件名:en_windows_7_enterprise_with_sp1_x64_dvd_u_677651.isoSHA1:A491F985DCCFB5 ...

  6. 【MySQL】Mariadb主从复制

    Mariadb主从复制 环境配置: Master : 172.30.200.200 Slave : 172.30.200.204 架构图,如下: Master的配置: 1.binlog配置 [root ...

  7. border和outline的区别

    如果有一个需求,给一个元素增加一条边框,想必大家会习惯且娴熟的使用border来实现,我也是这样   但其实outline也能达到同样的效果,并且在有些场景下会更适用,比如下面的demo 使用bord ...

  8. tensorflow之tf.stop_gradient

    停止梯度计算. 当在一个图中执行时, 这个op按原样输出它的输入张量. 当构建ops来计算梯度时,该op会阻止将其输入贡献考虑在内. 参数: Input: 一个张量. name: 操作的名称(可选) ...

  9. SampleDateFormat 高并发下导致 线程 Blocked 从而导致 Tomcat 吞吐一直上不去

    SampleDateFormat 高并发下导致 线程 Blocked 从而导致 Tomcat 吞吐一直上不去

  10. Entity Framework 6 中如何获取 EntityTypeConfiguration 的 Edm 信息?(二)

    接着上一篇 直接贴代码了: using System; using System.Collections.Generic; using System.Data.Entity; using System ...