java.lang.IllegalStateException: availableProcessors is already set to [8], rejecting [8]

本文解决了一个常见的问题,即SpringBoot项目整合Elasticsearch时启动报错,错误信息为“availableProcessorsisalreadysetto[8],rejecting[8]”。通过在启动类中使用@PostConstruct注解的方法来设置系统属性,成功解决了netty冲突导致的问题。

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");
    }

解决~

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值