当前位置: 首页 > 知识库问答 >
问题:

SOLR的执行器健康检查给出了创建名为“SOLR Client”的bean时的错误

易星纬
2023-03-14
    null
import org.springframework.boot.actuate.health.AbstractHealthIndicator;
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.Status;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.request.CoreAdminRequest;
import org.apache.solr.client.solrj.response.CoreAdminResponse;
import org.apache.solr.common.params.CoreAdminParams;


public class SolrHealthIndicator extends AbstractHealthIndicator {

    private final SolrClient solrClient;

    public SolrHealthIndicator(SolrClient solrClient) {
        super("Solr health check failed");
        this.solrClient = solrClient;
    }

    @Override
    protected void doHealthCheck(Health.Builder builder) throws Exception {
         Object status = this.solrClient.ping().getResponse().get("status");
            builder.up().withDetail("solrStatus", status);
//      CoreAdminRequest request = new CoreAdminRequest();
//      request.setAction(CoreAdminParams.CoreAdminAction.STATUS);
//      CoreAdminResponse response = request.process(this.solrClient);
//      int statusCode = response.getStatus();
//      Status status = (statusCode != 0) ? Status.DOWN : Status.UP;
//      builder.status(status).withDetail("status", statusCode);
    }
}
import javax.inject.Inject;
import javax.inject.Named;

import org.apache.solr.client.solrj.SolrClient;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration
public class ActuatorConfiguration {

    @Inject
    @Named("solrClient")
    private SolrClient solr;

    @ConditionalOnProperty(value = "solr.health.check.enabled",havingValue = "true")
    @Bean(name = "SearchStorage")
    public HealthIndicator solrHealthIndicator() {
        return new SolrHealthIndicator(solr);
    }
}

3)pom.xml

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
        </dependency>
        
       <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

<dependency>
    <groupId>org.apache.solr</groupId>
    <artifactId>solr-solrj</artifactId>
    <version>5.4.0</version>
</dependency>
<dependency>
    <groupId>org.apache.solr</groupId>
    <artifactId>solr-core</artifactId>
    <version>5.4.0</version>
</dependency>
<dependency>
  <groupId>javax.inject</groupId>
  <artifactId>javax.inject</artifactId>
  <version>1</version>
</dependency>

4)完整堆栈跟踪

2020-08-28 23:56:28.113  WARN 83950 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'actuatorConfiguration': Unsatisfied dependency expressed through field 'solr'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'solrClient' defined in class path resource [org/springframework/boot/autoconfigure/solr/SolrAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.solr.client.solrj.SolrClient]: Factory method 'solrClient' threw exception; nested exception is java.lang.NoClassDefFoundError: org/apache/solr/client/solrj/impl/HttpSolrClient$Builder
2020-08-28 23:56:28.116  INFO 83950 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2020-08-28 23:56:28.130  INFO 83950 --- [           main] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-08-28 23:56:28.134 ERROR 83950 --- [           main] o.s.boot.SpringApplication               : Application run failed

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'actuatorConfiguration': Unsatisfied dependency expressed through field 'solr'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'solrClient' defined in class path resource [org/springframework/boot/autoconfigure/solr/SolrAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.solr.client.solrj.SolrClient]: Factory method 'solrClient' threw exception; nested exception is java.lang.NoClassDefFoundError: org/apache/solr/client/solrj/impl/HttpSolrClient$Builder
..

    at com.test.sre.blue.BlueApplication.main(BlueApplication.java:18) ~[classes/:na]
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'solrClient' defined in class path resource [org/springframework/boot/autoconfigure/solr/SolrAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.solr.client.solrj.SolrClient]: Factory method 'solrClient' threw exception; nested exception is java.lang.NoClassDefFoundError: org/apache/solr/client/solrj/impl/HttpSolrClient$Builder
    at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:655) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
    …..
    ... 20 common frames omitted
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.solr.client.solrj.SolrClient]: Factory method 'solrClient' threw exception; nested exception is java.lang.NoClassDefFoundError: org/apache/solr/client/solrj/impl/HttpSolrClient$Builder
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
    at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:650) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
    ... 33 common frames omitted
Caused by: java.lang.NoClassDefFoundError: org/apache/solr/client/solrj/impl/HttpSolrClient$Builder
    at org.springframework.boot.autoconfigure.solr.SolrAutoConfiguration.solrClient(SolrAutoConfiguration.java:51) ~[spring-boot-autoconfigure-2.3.3.RELEASE.jar:2.3.3.RELEASE]
    ..at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
    ... 34 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.apache.solr.client.solrj.impl.HttpSolrClient$Builder
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581) ~[na:na]
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178) ~[na:na]
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522) ~[na:na]
    ... 40 common frames omitted

共有1个答案

何甫
2023-03-14

您连接了spring-boot-autoconfigure它有org.SpringFramework.Boot.AutoConfigure.Solr.Solr AutoConfigure.Solr

而这段代码正试图使用Solr4。并且在pom.xml中连接了Solr5。

在Solr5中,删除了org/apache/solr/client/solrj/impl/httpsolrclient$builder。

  • 禁用SolrAutoConfiguration。

我也不知道这一点,找到了如何在Grails 3.0.2中禁用SolrAutoConfiguration.class的解决方案

// Grails 4
@CompileStatic
@EnableAutoConfiguration(exclude = [org.springframework.boot.autoconfigure.solr.SolrAutoConfiguration.class])
class Application extends GrailsAutoConfiguration {
  • 或更新库
 类似资料:
  • 我需要改变频率来检查springboot执行器中的DB运行状况。默认DB运行状况检查查询每毫秒执行一次。我想让这个查询每1分钟后执行一次,而不是毫秒。有什么方法可以自定义它吗?

  • 我有一个实体类InAppNotification。看起来像这样的java: 我使用JPA来处理数据库查询,这就是JPA接口的定义: 这是我application.properties的样子: 但是,当我试图在构建后通过运行 来打包应用程序时,我会遇到以下问题: 尝试调用不存在的方法。尝试从以下位置进行:javax.el.ELManager.getExpress sionWorks(ELManage

  • 在将project从Spring Boot版本从1.2.3.release迁移到1.3.0.release之后,我已经开始得到以下异常。 创建类路径资源[org/springframework/boot/autoconfigure/admin/springapplicationadminjmxautoconfiguration.class]中定义的名为'Spring ApplicationAdmi

  • 我遵循本教程将消息发送到azure服务队列:https://docs.microsoft.com/en-us/azure/java/spring-framework/configure-spring-boot-starter-java-app-with-azure-service-bus 到我现有的spring boot应用程序,但我得到以下错误: 用户类别: 控制器类: pom xml: 添加它

  • 我试图将弹性搜索集成到spring-boot应用程序中,但我得到了这个*创建名为“client”的bean时出错*异常,不确定是什么地方出了问题,因为我之前找不到任何类似的线索...非常感谢你为大家指路。这是mu elasticsearch配置: 这是我的主要应用程序: 我的pom.xml: 这是te异常跟踪:

  • 我有这些错误编译,我不知道我哪里错了,我只有这3个类