Springboot中BaseHttpSolrClient報NoClassDefFoundError問題
SpringBoot升級之后, 被項目里面的solr坑了一把
SpringBoot目前版本: 2.3.9-RELEASE
Solrj版本: 7.7.3
因為是另一個同事升級的, 然后現在我負責上線了, 結果發測試環境的時候報BaseHttpSolrClient 這個類沒定義
查了一圈 發現 BaseHttpSolrClient 這個類是solr8.x里面的API, 但是我明明用的是7.7.3, 為什么啟動的時候會去加載這個配置?
然后發現那同事加了一個springboot-actuator在里面, 啟動的時候會對solr做一個健康檢查, 然后健康檢查用是那個actuator指定的solr版本(這里沒有詳細去研究)
解決方式:
1. 自定義Solr的健康檢查
2. 在啟動類@SpringBootApplication里面排除Solr健康檢查自動配置
@SpringBootApplication(exclude = {SolrHealthContributorAutoConfiguration.class})
public class Application {
public static void main(String[] args) throws Exception {
SpringApplication.run(Application.class, args);
}
}
org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext >> Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'documentationPluginsBootstrapper' defined in URL !/BOOT-INF/lib/springfox-spring-web-2.9.2.jar!/springfox/documentation/spring/web/plugins/DocumentationPluginsBootstrapper.class]: Unsatisfied dependency expressed through constructor parameter 1; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'webMvcRequestHandlerProvider' defined in URL [jar:file:/app/health-api/bin/health-api-feature_8.8-5125b190-20220609161601-8.8.0-SNAPSHOT.jar!/BOOT-INF/lib/springfox-spring-web-2.9.2.jar!/springfox/documentation/spring/web/plugins/WebMvcRequestHandlerProvider.class]: Unsatisfied dependency expressed through constructor parameter 1; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'webEndpointServletHandlerMapping' defined in class path resource [org/springframework/boot/actuate/autoconfigure/endpoint/web/servlet/WebMvcEndpointManagementContextConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.endpoint.web.servlet.WebMvcEndpointHandlerMapping]: Factory method 'webEndpointServletHandlerMapping' threw exception; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'healthEndpoint' defined in class path resource [org/springframework/boot/actuate/autoconfigure/health/HealthEndpointConfiguration.class]: Unsatisfied dependency expressed through method 'healthEndpoint' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'healthContributorRegistry' defined in class path resource [org/springframework/boot/actuate/autoconfigure/health/HealthEndpointConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.health.HealthContributorRegistry]: Factory method 'healthContributorRegistry' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'solrHealthContributor' defined in class path resource [org/springframework/boot/actuate/autoconfigure/solr/SolrHealthContributorAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.health.HealthContributor]: Factory method 'solrHealthContributor' threw exception; nested exception is java.lang.NoClassDefFoundError: org/apache/solr/client/solrj/impl/BaseHttpSolrClient$RemoteSolrException
本文來自博客園,作者:你啊347,轉載請注明原文鏈接:http://www.rzrgm.cn/LinKinSJ/p/16360010.html

浙公網安備 33010602011771號