elasticsearch5.6.1.集成springboot 遇到的坑

[ERROR]Failed to instantiate [org.elasticsearch.client.transport.TransportClient]: Factory method ‘elasticsearchClient’ threw exception; nested exception is java.lang.IllegalStateException: availableProcessors is already set to [8], rejecting [8]

翻译:[错误]未能实例化[org.elasticsearch.client.transport.TransportClient]:工厂方法“elasticsearchClient”引发异常;嵌套异常为java.lang.IllegalStateException:availableProcessors已设置为[8],拒绝[8]

在spring同时整合redis(短信服务),ES(elasticsearch,查询服务)时,会抛出以上异常

解决方案

方案1.启动类上加上一段代码

System.setProperty("es.set.netty.runtime.available.processors","false");

 

-----------------------

spring boot 集成redis和elasticsearch遇到的坑
起因是因为我在一个已经集成了redis的spring boot项目上引入了spring-data-elasticsearch包,配好环境之后开始报如下的错误。

Failed to instantiate [org.elasticsearch.client.transport.TransportClient]: Factory method 'elasticsearchClient' threw exception; nested exception is java.lang.IllegalStateException: availableProcessors is already set to [4], rejecting [4]
解决办法:

@SpringBootApplication

public class SpringBootExampleApplication {

 

public static void main(String[] args) {

System.setProperty("es.set.netty.runtime.available.processors","false");

SpringApplication.run(SpringbootexampleApplication.class, args);

}

}

  

原因:程序的其他地方使用了Netty,这里指redis。这影响在实例化传输客户端之前初始化处理器的数量。 实例化传输客户端时,我们尝试初始化处理器的数量。 由于在其他地方使用Netty,因此已经初始化并且Netty会对此进行防范,因此首次实例化会因看到的非法状态异常而失败。

posted @ 2021-09-04 11:16  panchanggui  阅读(419)  评论(0编辑  收藏  举报