spring boot项目整合elasticsearch,启动报错:
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]
各种百度,大多是建议在启动类的main方法中添加:
System.setProperty("es.set.netty.runtime.available.processors", "false");
即将main方法改写为:
/**
* 入口主函数
*
* @param args
*/
public static void main(String[] args) {
//解决netty冲突
System.setProperty("es.set.netty.runtime.available.processors", "false");
SpringApplication.run(BossApplication.class, args);
}
但是我这边这样改木有用。
后来,找到了
java.lang.IllegalStateException: availableProcessors is already set to [8], rejecting [8]
这篇博客,参考里头的方案,在启动类中添加了一个初始化方法:
@PostConstruct
void init() {
System.setProperty("es.set.netty.runtime.available.processors", "false");
}
解决~