我试图在SpringBoot 1.4中使用Jest 0.0.6 ElasticSearch客户端并出现以下错误。我认为这是因为SpringBoot尝试自动创建一个Jest Client以及一个健康检查,但旧的Jest客户端没有一些必需的类。
任何想法如何绕过这个?
我需要连接到旧的ElasticSearch v0.90.5服务器,此时我无法升级。如果您对如何最好地从SpringBoo连接到这样一个旧版本有任何想法,这也会非常有帮助。
Caused by:org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'metricsEndpointMetricReader' defined in class path resource
...
[org/springframework/boot/actuate/autoconfigure/ElasticsearchHealthIndicatorConfiguration$ElasticsearchJestHealthIndicatorConfiguration.class]:
Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.health.HealthIndicator]:
Factory method 'elasticsearchHealthIndicator' threw exception; nested exception is java.lang.NoClassDefFoundError: io/searchbox/action/Action; nested exception is
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.actuate.autoconfigure.EndpointAutoConfiguration ': Bean instantiation via constructor failed; nested exception is
org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.autoconfigure.EndpointAutoConfiguration$$EnhancerBySpringCGLIB$$909d8b5d]: Constructor threw exception; nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'elasticsearchHealthIndicator' defined in class path resource [org/springframework/boot/actuate/autoconfigure/ElasticsearchHealthIndicatorConfiguration$ElasticsearchJestHealthIndicatorConfiguration.class]: Bean instantiation via factory method failed; nested exception is
org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.health.HealthIndicator]: Factory method 'elasticsearchHealthIndicator' threw exception; nested exception is java.lang.NoClassDefFoundError: io/searchbox/action/Action
从Spring Boot 1.4发行说明:
" Jest支持
如果Jest在类路径上,则Spring Boot会自动配置JestClient和专用的HealthIndicator。这允许您使用Elasticsearch,即使spring-data-elasticsearch不在类路径上。"
答案 0 :(得分:1)
我在这个jest github页面中找到了。如果您使用es 0.90.5,则必须使用jest 0.0.6
。并且,有一个spring boot依赖项parent,指定jest的版本为2.0.3
:
<jest.version>2.0.3</jest.version>
自动配置代码位于:org.springframework.boot.autoconfigure.elasticsearch.jest.JestAutoConfiguration
将io.searchbox.client.JestClient
添加到类路径时,将加载此自动配置类。
这是由Condition
框架@ConditionalOnClass(JestClient.class)
建立的。
您可以找到有关条件框架here
的更多信息通过将exclude添加到启动类来排除此自动配置:
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.elasticsearch.jest.JestAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
@SpringBootApplication
@EnableAutoConfiguration(exclude = { JestAutoConfiguration.class})
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
}
将此排除添加到您启动课程后。你可以配置你拥有的jest客户端。