博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
SpringBoot整合Spring Data Solr
阅读量:4364 次
发布时间:2019-06-07

本文共 1492 字,大约阅读时间需要 4 分钟。

此文不讲solr相关,只讲整合,内容清单如下

1. maven依赖坐标

2. application.properties配置

3. Java Config配置

 

 

1. maven坐标

org.springframework.boot
spring-boot-starter-data-solr

2. application.properties配置

注意,这里的 spring.data.solr.core 不是框架提供的,在idea中会提醒

# solr spring.data.solr.host=http://localhost:8080/solr spring.data.solr.core=collection1

 

3. Java Config配置

这里主要是配置一下SolrTemplate,默认情况下 solr的starter是不提供这个bean的。

注意的地方就是HttpSolrServer要导对包

import org.apache.solr.client.solrj.impl.HttpSolrServer; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.data.solr.core.SolrTemplate; import org.springframework.data.solr.core.convert.SolrJConverter; @Configuration public class SolrConfig {
@Value("${spring.data.solr.host}") private String solrHost; @Value("${spring.data.solr.core}") private String solrCore; /** * 配置SolrTemplate */ @Bean public SolrTemplate solrTemplate() {
HttpSolrServer solrServer = new HttpSolrServer(solrHost); SolrTemplate template = new SolrTemplate(solrServer); template.setSolrCore(solrCore); // 2018-03-12晚更新,此处不需要加这句话,反而加了之后会导致solr域和实体类字段不同名时,导致无法将值映射到实体类字段中,此时会抛出异常,所以这里不需要加下面这句话 // template.setSolrConverter(new SolrJConverter()); return template; } }
 

转载于:https://www.cnblogs.com/kazetotori/p/8549458.html

你可能感兴趣的文章
Servlet
查看>>
基于jquery地图特效全国网点查看代码
查看>>
【leetcode】867 - Transpose Matrix
查看>>
selenium动作链
查看>>
敏捷外包工程系列之二:人员结构(敏捷外包工程,敏捷开发,产品负责人,客户价值)...
查看>>
《设计你的人生》的部分经典语录
查看>>
mustache多次渲染和多个赋值
查看>>
Web 前端开发精华文章推荐(HTML5、CSS3、jQuery)【系列二十三】
查看>>
linux-nohup命令
查看>>
[LeetCode OJ] Roman to Integer
查看>>
三次握手和四次挥手
查看>>
Redis的简单动态字符串实现
查看>>
putty network error:software caused connection abort
查看>>
存储过程 <3> 和函数的区别
查看>>
高级service之ipc ADIL用法
查看>>
Django框架-基础篇
查看>>
Leetcode: Binary Tree Maximum Path Sum
查看>>
通过虚拟环境创建并开始一个django
查看>>
关于 input[type="button"] , button
查看>>
Android ViewDragHelper全然解析 自己定义ViewGroup神器
查看>>