spingboot 2.1.3 与 elasticsearch7 兼容问题

pom 加入 elasticsearch7  的依赖,

        
            org.elasticsearch
            elasticsearch
            7.3.1
        
        
            org.elasticsearch.client
            transport
            7.3.1
        
        
            org.elasticsearch.client
            elasticsearch-rest-client
            7.3.1
        
        
            org.elasticsearch.client
            elasticsearch-rest-high-level-client
            7.3.1
        

 

然后做过简单的测试, 发现了错误 :

java.lang.NoSuchMethodError: org.elasticsearch.common.logging.Loggers.getLogger(Ljava/lang/String;)Lorg/apache/logging/log4j/Logger;

    at org.elasticsearch.transport.netty4.Netty4InternalESLogger.(Netty4InternalESLogger.java:34)
    at org.elasticsearch.transport.netty4.Netty4Utils$1.newInstance(Netty4Utils.java:53)
    at io.netty.util.internal.logging.InternalLoggerFactory.getInstance(InternalLoggerFactory.java:93)
    at io.netty.util.internal.logging.InternalLoggerFactory.getInstance(InternalLoggerFactory.java:86)
    at io.netty.util.internal.PlatformDependent.(PlatformDependent.java:70)
    at io.netty.util.ConstantPool.(ConstantPool.java:32)
    at io.netty.util.AttributeKey$1.(AttributeKey.java:27)
    at io.netty.util.AttributeKey.(AttributeKey.java:27)
    at org.elasticsearch.transport.netty4.Netty4Transport.(Netty4Transport.java:231)
    at org.elasticsearch.transport.Netty4Plugin.getSettings(Netty4Plugin.java:56)
    at org.elasticsearch.plugins.PluginsService.lambda$getPluginSettings$0(PluginsService.java:89)
    at java.util.stream.ReferencePipeline$7$1.accept(ReferencePipeline.java:267)
    at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1382)
    at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
    at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
    at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
    at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
    at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499)
    at org.elasticsearch.plugins.PluginsService.getPluginSettings(PluginsService.java:89)
    at org.elasticsearch.client.transport.TransportClient.buildTemplate(TransportClient.java:156)
    at org.elasticsearch.client.transport.TransportClient.(TransportClient.java:296)
    at org.elasticsearch.transport.client.PreBuiltTransportClient.(PreBuiltTransportClient.java:130)
    at org.elasticsearch.transport.client.PreBuiltTransportClient.(PreBuiltTransportClient.java:116)
    at org.elasticsearch.transport.client.PreBuiltTransportClient.(PreBuiltTransportClient.java:106)
    at com.lkk.es.EsTest.testAaa(EsTest.java:30)
    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.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
    at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
    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 com.intellij.rt.execution.CommandLineWrapper.main(CommandLineWrapper.java:66)

 

也真不知道 是咋回事!奇葩!

 

仔细检查 7.3.1 ,org.elasticsearch.common.logging.Loggers.getLogger  ,发现确实有那个 方法, 但是 实际上 引用的是 6.4.3 !!

 

仔细检查错误日志,发现org.elasticsearch.transport.netty4.Netty4InternalESLogger 竟然是 6.4.3 的jar, 进一步往上跟,发现 org.elasticsearch.transport.Netty4Plugin 也是 , 再往上走就是正常的 7.3.1了!

 

原因已经基本清楚了, 就是 jar 的依赖 的引入哪里出了问题。 我的 spingboot 是 2.1.3, 默认是没有 elasticsearch的吧

 

 

怎么解决呢?

 

首先,为什么会这样的问题? pom问题? 仔细检查了 pom 的依赖吗没有发现有 任何 transport-netty4-client-6.4.3 的引用啊! 倒是发现了 transport-netty4-client-7.3.1 ! 这样看来就奇怪了! 难道是 隐藏的 依赖?

 

需要指定 elasticsearch.version 吗? 试了, 好像也没有用。。

 

仔细检查pom

"1.0" encoding="UTF-8"?>
"http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    
        test_system
        com.lkk
        2.2.0.GA
    
    4.0.0
    test_system_viewController
    jar
    test_system_viewController
    http://maven.apache.org
    
        UTF-8
        7.3.1
    

    
        
            com.lkk
            test_system_domain
        

        
            com.google.code.gson
            gson
            2.8.5
        

        
            org.elasticsearch
            elasticsearch
            7.3.1
        
        
            org.elasticsearch.client
            transport
            7.3.1
        
        
            org.elasticsearch.client
            elasticsearch-rest-client
            7.3.1
        
        
            org.elasticsearch.client
            elasticsearch-rest-high-level-client
            7.3.1
        


    

aa

加入:


     org.springframework.boot
     spring-boot-starter-data-elasticsearch

试试。 发现..  没卵用。 难道是 上级  父 pom 引入的?

 

        
            com.lkk
            test_system_domain
        

放到了 dependencies 的最下面。 就好了! ( 后面 再复原,竟然重现不了, )

 

 

哦, 我 觉得应该是 缓存的原因吧! 可能是 spring-boot-starter-data-elasticsearch 引入的 elasticsearch 是6.4.3, 然后一直 有缓存。。 需要通过某种手段把它清理才行!

 

 

参考:

https://stackoverflow.com/questions/57508456/how-to-correct-the-classpath-of-your-application-so-that-it-contains-a-single

 

你可能感兴趣的:(spingboot 2.1.3 与 elasticsearch7 兼容问题)