首页 > 编程语言 > 详细

SpringBoot整合Spring Data Solr

时间:2018-03-12 15:53:39      阅读:1832      评论:0      收藏:0      [点我收藏+]

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

1. maven依赖坐标

2. application.properties配置

3. Java Config配置

 


1. maven坐标

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-solr</artifactId>
</dependency>


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);
template.setSolrConverter(new SolrJConverter());
return template;
}
}

SpringBoot整合Spring Data Solr

原文:https://www.cnblogs.com/kazetotori/p/8549458.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!