SpringCloud 集成 ES 问题 java.lang.NoSuchMethodError

  • Springboot 版本为:2.2.5.RELEASE,SpringCloud 版本为:Hoxton.SR3,其中已集成了mybatis plus、redis。在集成 es 时当时引入包:
<dependency>
     <groupId>org.elasticsearch.client</groupId>
     <artifactId>elasticsearch-rest-high-level-client</artifactId>
     <version>6.1.3</version>
 </dependency>

出现了如下异常报错信息:

java.lang.NoSuchMethodError: org.elasticsearch.client.Request.<init>(Ljava/lang/String;Ljava/lang/String;)V
	at org.elasticsearch.client.RestClient.performRequest(RestClient.java:323)
	at org.elasticsearch.client.RestHighLevelClient.performRequest(RestHighLevelClient.java:443)
	at org.elasticsearch.client.RestHighLevelClient.performRequestAndParseEntity(RestHighLevelClient.java:429)
	at org.elasticsearch.client.RestHighLevelClient.search(RestHighLevelClient.java:368)
	at com.zsh.usercenter.service.impl.LogInfoServiceImpl.getLogInfoList(LogInfoServiceImpl.java:105)
	at com.zsh.usercenter.controller.LogInfoController.getLogInfoList(LogInfoController.java:45)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:190)
	at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138)
	at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:106)
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:879)
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:793)
	at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1040)
	... 53 common frames omitted

这个问题是因为包冲突导致,简单的通过 Dependencies Analyzer 进行排除后问题依然没有解决,于是从网上百度了一下。通过其中的解决方法无法解决,于是我仔细查看 maven 引入的关于 es 具体有哪些包,从中发现如下:
在这里插入图片描述
发现我只想引入 elasticsearch-rest-high-level-client 6.1.3 版本,但是实际引入还引入了 elasticsearch 6.8.6 版本和 elasticsearch-rest-client 6.8.6 版本,于是通过将 elasticsearch-rest-high-level-client 中的 elasticsearchelasticsearch-rest-client 排除重新引入解决问题。

<dependency>
            <groupId>org.elasticsearch.client</groupId>
            <artifactId>elasticsearch-rest-high-level-client</artifactId>
            <version>6.1.3</version>
            <exclusions>
                <exclusion>
                    <groupId>org.elasticsearch</groupId>
                    <artifactId>elasticsearch</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.elasticsearch.client</groupId>
                    <artifactId>elasticsearch-rest-client</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.elasticsearch.client</groupId>
            <artifactId>elasticsearch-rest-client</artifactId>
            <version>6.1.3</version>
        </dependency>
        <dependency>
            <groupId>org.elasticsearch</groupId>
            <artifactId>elasticsearch</artifactId>
            <version>6.1.3</version>
        </dependency>

总结

对于这件事解决方法很简单,但是我花了将近一个小时去解决这问题,主要问题在于一开始思路就不对,应该去查看实际项目中引入的包,而不是一味的从百度获取解决方案,特别是对于这种场景比较复杂的包冲突,从而可以快速排查问题,节省时间。

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

lytao123

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值