我正在研究在springboot中使用solr,我尝试了一本书上的程序,书中的spring-boot-starter-parent版本是2.1.2.RELEASE:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
虽然我的 spring-boot-starter-parent 版本是 2.6.4:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.4</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
我在 pom.xml 中添加了 solr 依赖项,如下所示:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-solr</artifactId>
</dependency>
但是 pom.xml 显示错误:版本不能为空,所以我转到 https://mvnrepository.com/发现最新的 spring-boot-starter-data-solr 版本是 2.4.13,所以我像这样添加 solr 依赖:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-solr</artifactId>
<version>2.4.13</version>
</dependency>
现在pom.xml已经没有错误了,但是导入solr的java程序仍然无法运行,如:
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServerException;
它找不到任何关于 solr 的类。我还尝试在 https://mvnrepository.com/ 下载 spring-boot-starter-data-solr jar ,我在本地导入它,但我只在下载的 spring-boot-starter-data-solr jar 中找到一个 META-INF 文档,它没有任何类
那么我应该如何在springboot中使用solr呢?
最佳答案
Apache Solr 项目的 Spring Data has been discontinued 。因此,它在 2021.0.0 版本 and from Spring Boot in its 2.5.0 release 中从 Spring Data 版本系列中删除。 .
如果您直接使用 Solr,而不是通过 Spring Data,则可以继续这样做。您必须直接声明 Solr 依赖项,而不是依赖 Data Solr 启动器,并且必须在应用程序中配置 Solr,而不是依赖 Spring Boot 的自动配置来执行此操作。
关于spring-boot - 如何在 Spring Boot 2.6.4 中导入 spring-boot-starter-data-solr,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71426714/