java 整合solr_SpringBoot整合Spring Data Solr
此文不講solr相關(guān),只講整合,內(nèi)容清單如下
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);
template.setSolrConverter(new SolrJConverter());
return template;
}
}
總結(jié)
以上是生活随笔為你收集整理的java 整合solr_SpringBoot整合Spring Data Solr的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java跨域权重_爱站权重查询 API
- 下一篇: 奥迪A6L大灯多少钱?