如何在 spring boot 2.6.4 中导入 spring-boot-starter-data-solr

how to import spring-boot-starter-data-solr in spring boot 2.6.4

我正在学习在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没有报错,但是java导入solr的程序还是不行,如:

import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServerException;

它找不到任何关于 solr 的 class。我也尝试在https://mvnrepository.com/中下载spring-boot-starter-data-solr jar,并在本地导入,但我只在spring中找到一个META-INF文件-下载了 boot-starter-data-solr jar,它没有任何 classes

那么我应该如何在 springboot 中使用 solr?

Apache Solr 项目的 Spring 数据 has been discontinued. As a result, it was removed from the Spring Data release train in its 2021.0.0 release and from Spring Boot in its 2.5.0 release

如果您直接使用 Solr,而不是通过 Spring 数据,您可以继续这样做。您将必须直接声明您的 Solr 依赖项而不是依赖 Data Solr 启动器,并且您将必须在您的应用程序中配置 Solr 而不是依赖 Spring Boot 的 auto-configuration 来这样做。