当前位置:   article > 正文

springboot整合bboss 报 No qualifying bean of type ‘org.frameworkset.elasticsearch.boot.BBossESStarter

springboot整合bboss 报 No qualifying bean of type ‘org.frameworkset.elasticsearch.boot.BBossESStarter

一、现象描述

在spring boot项目中引入 bboss es starter相关依赖之后,跑测试类,发生报错:

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.frameworkset.elasticsearch.boot.BBossESStarter' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1824)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1383)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1337)
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.resolveFieldValue(AutowiredAnnotationBeanPostProcessor.java:773)
	... 76 common frames omitted

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.dromara.test.ElasticDsRecordInfoTest': Unsatisfied dependency expressed through field 'bBossESStarter': No qualifying bean of type 'org.frameworkset.elasticsearch.boot.BBossESStarter' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

这个错误org.springframework.beans.factory.NoSuchBeanDefinitionException表示Spring框架在尝试自动装配(autowire)一个类型为org.frameworkset.elasticsearch.boot.BBossESStarter的bean时失败了,因为它没有在Spring的应用上下文中找到一个合格的bean候选者。说白了,就是BBossESStarter没有被注入进来

试着启动一下springboot的main方法,看看控制台是否有es相关的初始化信息,发现完全没有加载es信息
在这里插入图片描述

二、排查配置

1、检查maven配置,看了未发现什么问题

<dependency>
            <groupId>com.bbossgroups.plugins</groupId>
            <artifactId>bboss-elasticsearch-spring-boot-starter</artifactId>
            <version>7.1.3</version>
            <exclusions>
                <exclusion>
                    <artifactId>slf4j-log4j12</artifactId>
                    <groupId>org.slf4j</groupId>
                </exclusion>
            </exclusions>
        </dependency>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

2、yml文件配置es连接参数信息,也都配置了,没有遗漏的

spring:
  elasticsearch:
      bboss:
        elasticUser: elastic
        elasticPassword: password123
        elasticsearch:
          rest:
            hostNames: 192.168.8.25:9200,192.168.8.26:9200,192.168.8.27:9200  ##集群地址配置
          dateFormat: yyyy.MM.dd
          timeZone: Asia/Shanghai
          showTemplate: true
          discoverHost: false
        dslfile:
          refreshInterval: -1
        http:
          timeoutConnection: 5000
          timeoutSocket: 5000
          connectionRequestTimeout: 5000
          retryTime: 1
          maxLineLength: -1
          maxHeaderCount: 200
          maxTotal: 400
          defaultMaxPerRoute: 200
          soReuseAddress: false
          soKeepAlive: false
          timeToLive: 3600000
          keepAlive: 3600000
          keystore:
          keyPassword:
          hostnameVerifier:
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30

三、顺藤摸瓜

刚刚报错是通过测试类发现的,我们就通过测试类来排查,测试类代码如下:

package org.dromara.test;
import org.frameworkset.elasticsearch.boot.BBossESStarter;
import org.frameworkset.elasticsearch.client.ClientInterface;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.List;
import java.util.Map;

@SpringBootTest
public class ElasticDsRecordInfoTest {

    @Autowired
    private BBossESStarter bBossESStarter;

    @Test
    public void testsql() throws InterruptedException {
        ClientInterface restClient = bBossESStarter.getRestClient();
        System.out.println(restClient);
        String  result = restClient.executeHttp("/_stats",ClientInterface.HTTP_GET);
        System.out.println(result);
    }

}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27

打断点进入到BBossESStarter 类中,看底层源码
在这里插入图片描述
启动测试类,发现根本都没有进入start方法里面,所以yml文件配置的es参数信息,根本没有起作用。

四、解决办法

查询了大量的资料,最终在官网找到了答案,是因为springboot和bboss的版本问题导致,具体版本对应如下:

  • spring boot 1.x,2.x依赖包
<dependency>
    <groupId>com.bbossgroups.plugins</groupId>
   <artifactId>bboss-elasticsearch-spring-boot-starter</artifactId>
    <version>7.1.7</version>
</dependency>
  • 1
  • 2
  • 3
  • 4
  • 5
  • spring boot 3.x依赖包
<dependency>
    <groupId>com.bbossgroups.plugins</groupId>
   <artifactId>bboss-elasticsearch-spring-boot3-starter</artifactId>
    <version>7.1.7</version>
</dependency>
  • 1
  • 2
  • 3
  • 4
  • 5

而本文报错的springboot项目版本是 3.1.7
在这里插入图片描述
maven依赖的bboss版本是7.1.3
在这里插入图片描述
所以,按照官网,应该把maven依赖修改为

<dependency>
    <groupId>com.bbossgroups.plugins</groupId>
   <artifactId>bboss-elasticsearch-spring-boot3-starter</artifactId>
    <version>7.1.7</version>
</dependency>
  • 1
  • 2
  • 3
  • 4
  • 5

五、运行测试

修改完maven依赖之后,我们启动一下springboot的main方法,看一下控制台是否有es相关的初始化信息
在这里插入图片描述
现在发现有es连接成功信息了,说明生效了。问题解决

六、总结

spring注入BBossESStarter失败,是由于springboot和bboss的版本不一致造成,具体版本对照如下

  • spring boot 1.x,2.x依赖包
<dependency>
    <groupId>com.bbossgroups.plugins</groupId>
   <artifactId>bboss-elasticsearch-spring-boot-starter</artifactId>
    <version>7.1.7</version>
</dependency>
  • 1
  • 2
  • 3
  • 4
  • 5
  • spring boot 3.x依赖包
<dependency>
    <groupId>com.bbossgroups.plugins</groupId>
   <artifactId>bboss-elasticsearch-spring-boot3-starter</artifactId>
    <version>7.1.7</version>
</dependency>
  • 1
  • 2
  • 3
  • 4
  • 5
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/花生_TL007/article/detail/371148
推荐阅读
相关标签
  

闽ICP备14008679号