在 solr 9+ 中使用 Http2SolrClient 构建器时如何修复 NoClassDefFoundError?

问题描述 投票:0回答:1

我在我的项目中使用

maven
以及此依赖项:

<dependency>
  <groupId>org.apache.solr</groupId>
  <artifactId>solr-solrj</artifactId>
  <version>9.2.0</version>
</dependency>

Java版本:

17

SpringBoot版本:

2.7.13

代码中的用法:

@Bean
public SolrClient solrClient() {
  return new Http2SolrClient.Builder(host).build();
}

我有正确的主机与

HttpSolrClient
(已弃用)一起使用,但不与
Http2SolrClient
一起使用。

构建正常 - 应用程序运行时出错:

Caused by: java.lang.NoClassDefFoundError: org/eclipse/jetty/http/HttpFields$Mutable
at org.apache.solr.client.solrj.impl.Http2SolrClient$Builder.<init> 
(Http2SolrClient.java:992)

我尝试添加任何版本的

org.eclipse.jetty
- 没有帮助。

在文档中 - 版本 9.2.0 应该支持 Http2SolrClient: https://solr.apache.org/docs/9_2_0/solrj/org/apache/solr/client/solrj/impl/Http2SolrClient.html

如何正确创建一个工作的 Http2SolrClient?

java solr
1个回答
0
投票

看来我找到了答案,这个问题是几个月前在这里咨询的:

https://issues.apache.org/jira/browse/SOLR-16668?jql=text%20~%20%22Http2SolrClient%20HttpFields%22

所以

"forcing all the jetty dependencies to a specific version"
适用于这种情况:

dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
implementation group: 'org.apache.solr', name: 'solr-solrj', version: '9+'
implementation group: 'org.eclipse.jetty.http2', name: 'http2-client', version: '10.0.13'
implementation group: 'org.eclipse.jetty.http2', name: 'http2-common', version: '10.0.13'
implementation group: 'org.eclipse.jetty.http2', name: 'http2-hpack', version: '10.0.13'
implementation group: 'org.eclipse.jetty.http2', name: 'http2-http-client-transport', version: '10.0.13'
implementation group: 'org.eclipse.jetty', name: 'jetty-util', version: '10.0.13'
implementation group: 'org.eclipse.jetty', name: 'jetty-io', version: '10.0.13'
implementation group: 'org.eclipse.jetty', name: 'jetty-http', version: '10.0.13'
implementation group: 'org.eclipse.jetty', name: 'jetty-client', version: '10.0.13'
implementation group: 'org.eclipse.jetty', name: 'jetty-alpn-client', version: '10.0.13'
implementation group: 'org.eclipse.jetty', name: 'jetty-alpn-java-client', version: '10.0.13'
}

" the problem I have with SolrJ 9.2.0 is caused somehow by Spring Boot, because they override the version of Jetty."

© www.soinside.com 2019 - 2024. All rights reserved.