在上一篇中已经讲解了如何使用docker安装Solr,本篇讲解一下在SpringBoot项目中如何简单集成solr。在你现有搭建的SpringBoot项目基础上增加如下的pom依赖:
<dependency>
<groupId>com.github.magese</groupId>
<artifactId>ik-analyzer</artifactId>
<version>8.5.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-solr</artifactId>
<version>2.4.11</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.10</version>
</dependency>
HttpSolrClient注入
@Bean
public HttpSolrClient solrClient() {
CredentialsProvider provider = new BasicCredentialsProvider();