美文网首页
spring cloud 单元测试 es报错availableP

spring cloud 单元测试 es报错availableP

作者: 狗皮膏药w | 来源:发表于2021-07-08 16:44 被阅读0次

    报错信息

    beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'elasticsearchTemplate' defined in class path resource [org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchDataAutoConfiguration.class]: Unsatisfied dependency expressed through method 'elasticsearchTemplate' parameter 0; nested exception is 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 [16], rejecting [16]

    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject

    availableProcessors is already set to [16], rejecting [16]

    单元测试类加

    static {

    System.setProperty("es.set.netty.runtime.available.processors", "false");

    }

    可以解决

    可以抽出一个类,复制启动类中的注解配置,加上上面那段代码,然后test类引用。

    @SpringBootTest(classes = TestApplication.class)

    相关文章

      网友评论

          本文标题:spring cloud 单元测试 es报错availableP

          本文链接:https://www.haomeiwen.com/subject/dkstpltx.html