Springboot整合Elasticsearch报错availableProcessors is already set to [4], rejecting [4]

时间:2023-12-22 13:23:50

Springboot整合Elasticsearch报错

今天使用SpringBoot整合Elasticsearch时候,相关的配置完成后,启动项目就报错了。

nested exception is java.lang.IllegalStateException: availableProcessors is already set to [4], rejecting [4]

Springboot整合Elasticsearch报错availableProcessors is already set to [4], rejecting [4]

我网上查询了一下,有人是是因为整合了Redis的原因。但是我把Redis相关的配置去掉后,问题还是没有解决,最后有人说是因为netty冲突的问题。
也有人给出了解决方式就是在项目初始化钱设置一下一个属性。在初始化之前加上System.setProperty(“es.set.netty.runtime.available.processors”, “false”);

@Configuration
public class ElasticSearchConfig {
@PostConstruct
void init() {
System.setProperty("es.set.netty.runtime.available.processors", "false");
}
}

我按照这种方法还是没有解决我这边项目的问题。
最后我直接把System.setProperty(“es.set.netty.runtime.available.processors”, “false”);
发现这样可以解决我这边的问题。

@SpringBootApplication
public class EurekaBussnissServiceUserApplication { public static void main(String[] args) {
// System.out.println("===========================================");
/**
* Springboot整合Elasticsearch 在项目启动前设置一下的属性,防止报错
* 解决netty冲突后初始化client时还会抛出异常
* java.lang.IllegalStateException: availableProcessors is already set to [4], rejecting [4]
*/
System.setProperty("es.set.netty.runtime.available.processors", "false");
SpringApplication.run(EurekaBussnissServiceUserApplication.class, args);
}
}