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

posted @ 2022-06-09 17:05  你啊347  阅读(435)  评论(0编辑  收藏  举报