Java接收solr动态域_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 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 specMap;//最好将范型加上
//set() get()略
因为是Maven分模块开发,将POJO重新install就可以了
2019-07-1510:47:32
作者:深海收破烂
标签:java,data,springframework,报错,org,SolrTemplate,solr
来源: https://www.cnblogs.com/itboxue/p/11187550.html
Java接收solr动态域_Spring Data Solr创建动态域报错:org.springframework.data.solr.UncategorizedSolrException...相关推荐
- .net调用Oracle 报错:System.Data.OracleClient 需要 Oracle 客户端软件 8.1.7 或更高版本问题
我又重拾.net搞一搞.老本行了,不过现在已投奔java阵营. 用visual studio 2022运行asp.net程序,结果在读取数据库的时候报错: .net调用Oracle 报错:System ...
- 安装Windows补丁KB947821报错0x8007000d The data is invalid
背景: 域内有一个Windows Server的成员服务器需要安装补丁KB947821,安装补丁过程中一直报错0x8007000d The data is invalid. 排错过程: 使用命令行wu ...
- java 中for循环中重复定义的变量 为什么不报错?
java 中for循环中重复定义的变量 为什么不报错? public class Test1 {public static void main(String[] args) {int[] arr = ...
- java.sql.SQLException: Access denied for user ‘‘@‘localhost‘ (using password: NO)报错问题解决
java.sql.SQLException: Access denied for user ''@'localhost' (using password: NO)报错问题解决 参考文章: (1)jav ...
- mysql报错:1406, Data too long for column
mysql报错:1406, "Data too long for column pymysql.err.DataError: (1406, "Data too long for c ...
- The package javax.swing is not accessible(java GUI 编程时引用swing包和awt包时会报错怎么办)
Java GUI 编程时引用swing包和awt包时会报错怎么办 一.环境与错误现象 使用的编译器为eclipse,情况为: 二.解决方法 问题主要是由工程中的module-info.java这个文件 ...
- FFMpeg打开文件报错:Invalida data found when processing input
我这边出现的错误是打开mp4文件能打开,aac文件也能打开,但是打开mp3文件的时候就开始报错:Invalida data found when processing input. 在我测试的过程中发 ...
- Python中调用FRED报错ValueError: time data 'fred' does not match format '%Y-%m-%d'
Python中调用FRED报错ValueError: time data 'fred' does not match format '%Y-%m-%d' 小白一枚,刚学习python调用FRED等数据 ...
- ZooKeeper只完美解决Unable to read additional data from server sessionid 0x0报错问题,并带你深度理解ZooKeeper内部机制之选举机制
ZooKeeper只完美解决Unable to read additional data from server sessionid 0x0报错问题,并带你深度理解ZooKeeper内部机制之选举机制 ...
最新文章
- 静态变量与实例变量的区别
- apache php 调优_Apache的性能优化(二)
- Prometheus部署监控容器
- 浅谈深度学习(Deep Learning)的基本思想和方法
- Web框架之Django_02基本操作(Django项目启动配置、数据库连接、orm、增删改查)
- 2011年中国民营企业500强名单,广东仅13家浙江180家江苏130家
- 搭建一套ASP.NET Core+Nacos+Spring Cloud Gateway项目
- 北京计算机一级2020,2020北京市一级计算机基础及MS Office应用考试在线自测试题库(不限设备,登陆即可做题)...
- [转载] 中华典故故事(孙刚)——01 天要下雨_娘要嫁人
- 避免sql注入的方法
- 大数据集群安装02之Hadoop配置
- 利用MATLAB对乐曲进行钢琴演奏【matlab调音_1】
- springboot毕设项目银行助学贷款管理系统0o571(java+VUE+Mybatis+Maven+Mysql)
- fcm算法的MATLAB实现
- (四)keycloak 自定义用户(SPI)开发
- 树莓派+opencv+百度aip实现人脸识别并发置邮箱
- 既然选择了远方,便只顾风雨兼程
- mysql级联更新_Mysql实现级联操作(级联更新、级联删除)(转)
- 一种经典的客户关系管理系统(CRM)订单模型的设计与实现
- JAVA相关编译知识
热门文章
- MCU不再“芯慌慌”,国产新品Air101帮你忙
- xmpp, webrtc, webchat联想
- mysql5.7.16 表空间加密,MySQL :: MySQL 5.7参考手册:: A.16 MySQL 5.7 FAQ:InnoDB表空间加密...
- 女孩用自己的×××身来换取男友的健康
- 163 新闻页面网络爬虫简单抓取数据
- PMP认证与NPDP认证哪个含金量高?
- php hyper-v,win10自带播放器 rmvb_win 配置php_win 10 hyper-v
- Mac上抓包工具Charles的安装配置
- 华为鸿蒙龙头股一览表_华为鸿蒙概念股龙头一览?华为鸿蒙概念股有哪些(表)...
- pdm数据导出oracle,PowerDesigner使用(一):PDM文件导入Oracle数据库