1. 程式人生 > >SpringBoot整合ES+redis時報錯( org.springframework.beans.factory.UnsatisfiedDependencyException)

SpringBoot整合ES+redis時報錯( org.springframework.beans.factory.UnsatisfiedDependencyException)

1.異常資訊:

Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'postServiceImpl': Unsatisfied dependency expressed through field 'postRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'postRepository': Cannot resolve reference to bean 'elasticsearchTemplate' while setting bean property 'elasticsearchOperations'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'elasticsearchTemplate' defined in class path resource 

 Failed to instantiate [org.elasticsearch.client.transport.TransportClient]: Factory method 'elasticsearchClient' threw exception; nested exception is java.lang.IllegalStateException: availableProcessors is already set to [4], rejecting [4]

SpringBoot整合ES+redis時報錯, ‘elasticsearchTemplate’ 這個bean不能建立, 原因是不是初始化elasticsearchClient

2.解決辦法:

啟動類 main方法第一行加入如下配置

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