【问题标题】:how to import spring-boot-starter-data-solr in spring boot 2.6.4如何在 Spring Boot 2.6.4 中导入 spring-boot-starter-data-solr
【发布时间】:2022-11-10 09:21:51
【问题描述】:

我正在研究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?

【问题讨论】:

    标签: spring-boot maven solr


    【解决方案1】:

    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 的自动配置来执行此操作。

    【讨论】:

    • 你能在这里详细说明并提供一个例子吗?
    【解决方案2】:

    solr-solrj 可能是未更新的spring-data-solr 的更新替代品。

    【讨论】:

      猜你喜欢
      • 2017-02-09
      • 2021-01-18
      • 2021-02-09
      • 2015-06-13
      • 2021-11-11
      • 2014-04-07
      • 2019-06-23
      • 2014-12-29
      • 2016-11-12
      相关资源
      最近更新 更多