[ERROR]Factory method 'elasticsearchClient' threw exception

[ERROR]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]

我学的是 面向百度编程
elasticsearch 简称 ES

  1. 今天报这个错,用了我1个小时,整个心情都不好了

    项目中的依赖,Boot版本 2.1.9,ES版本 6.x

<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-data-elasticsearch</artifactId>
</dependency>
#Redis
spring.redis.host=129.28.000.000
spring.redis.port=6379

#elasticsearch
spring.data.elasticsearch.cluster-name=my_elasticsearch
spring.data.elasticsearch.cluster-nodes=127.0.0.1:9302
spring.data.elasticsearch.repositories.enabled=true
public interface SearchSkuInfoRepository 
	extends ElasticsearchRepository<SearchSkuInfo, Long> {}
  1. 启动就报错,Factory method ‘elasticsearchClient’ threw exception
    我去年写过 ES项目,当时并没有报错,就连以前写过的 ES测试项目也还在,
    对比了一下,关于ES的代码是一模一样
    ,可还是报错了

  2. 网上百度了一下,有人说缺下面这个依赖,但是我加了这个依赖,还是一样

<dependency>
    <groupId>org.elasticsearch.plugin</groupId>
    <artifactId>transport-netty4-client</artifactId>
    <version>6.2.3</version>
</dependency>
  1. 又百度了一下,说是 springBoot同时整合 Redis 和 ES 时,发生了冲突
    在启动类上这样写

@SpringBootApplication
public class YyscApplication{
    public static void main(String[] args) {
    	//看这里,加上这句话
        System.setProperty("es.set.netty.runtime.available.processors","false");
        SpringApplication.run(YyscApplication.class, args);
    }
}

  1. 可是我在测试类上还是报错了,百度上说这样写
@RunWith(SpringRunner.class)
@SpringBootTest
public class YyscApplicationTests {

    public YyscApplicationTests() {
    	//在构造函数上写上这个
        System.setProperty("es.set.netty.runtime.available.processors","false");
    }
    
  1. 问题解决了,没报错了。
    是最后一步起了作用,还是前面几步共同起的作用就不得而知了

面向百度编程
代码搬运工

  • 10
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 6
    评论
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值