在启动SpringApplication.run(SearchApplication.class,args)时,
如果有类似以下的报错, 可能是Springboot的netty版本冲突问题导致的
Caused by: java.lang.IllegalStateException: availableProcessors is already set to [8], rejecting [8]
Caused by: org.springframework.beans.BeanInstantiationException: 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]
解决netty冲突后初始化client时还会抛出异常的问题,
Springboot整合Elasticsearch 在项目启动前需要设置一下属性
在SpringApplication.run( ) 前面加一行代码 System.setProperty(“es.set.netty.runtime.available.processors”, “false”);
如下所示:
public class SearchApplication {
public static void main(String[] args) {
System.setProperty(“es.set.netty.runtime.available.processors”, “false”);
SpringApplication.run(SearchApplication.class,args);
}
}