錯誤詳細信息:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'elasticsearchClient'
defined in class path resource [org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchAutoConfiguration.class]:
Bean instantiation via factory method failed; nested exception is 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]
關鍵信息如下:
Caused by: java.lang.IllegalStateException: availableProcessors is already set to [8], rejecting [8]
通過關鍵字搜索,找到了解決辦法,原因是因為SpringBoot的netty和elasticsearch的netty相關jar沖突
只需在啟動類加入如下代碼即可解決(注意,這段代碼要放在SpringApplication.run(Application.class, args)之前才行,否則不會生效):
System.setProperty("es.set.netty.runtime.available.processors", "false");