springboot整合elasticsearch出错,Error creating bean TransportClient

Caused by: java.lang.NoSuchMethodError: io.netty.util.internal.ObjectUtil.checkPositive(ILjava/lang/String;)I
    at io.netty.util.NettyRuntime$AvailableProcessorsHolder.setAvailableProcessors(NettyRuntime.java:44) ~[netty-common-4.1.13.Final.jar:4.0.33.Final]
    at io.netty.util.NettyRuntime.setAvailableProcessors(NettyRuntime.java:87) ~[netty-common-4.1.13.Final.jar:4.0.33.Final]

 解决方法:springboot项目在初始化时设置         System.setProperty("es.set.netty.runtime.available.processors", "false");

@PostConstruct
    public void init() {
        //设置ES NETTY冲突
        System.setProperty("es.set.netty.runtime.available.processors", "false");
        log.info("application version 1.0 begin... ");
    }

解决netty冲突后初始化client时还会抛出异常,异常信息如下:

Caused by: java.lang.NoSuchMethodError: io.netty.buffer.CompositeByteBuf.addComponents(ZLjava/lang/Iterable;)Lio/netty/buffer/CompositeByteBuf;
    at org.elasticsearch.transport.netty4.Netty4Utils.toByteBuf(Netty4Utils.java:117) ~[transport-netty4-client-5.6.0.jar:5.6.0]
    at org.elasticsearch.transport.netty4.Netty4Transport.sendMessage(Netty4Transport.java:395) ~[transport-netty4-client-5.6.0.jar:5.6.0]

netty版本冲突,低版本的netty启动时会抛异常,需要添加高版本的netty依赖,请看maven依赖包 项,将两项添加到你的pom.xml既可,如果还有问题请留言

猜你喜欢

转载自blog.csdn.net/weixin_39986856/article/details/81410724