[ERROR]Factory method 'elasticsearchClient' threw exception

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/wy233333/article/details/102769460

[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. 问题解决了,没报错了。
    是最后一步起了作用,还是前面几步共同起的作用就不得而知了

面向百度编程
代码搬运工

猜你喜欢

转载自blog.csdn.net/wy233333/article/details/102769460