-
Notifications
You must be signed in to change notification settings - Fork 41.6k
Description
In my @SpringBootApplication class I define this restclient
@Bean(destroyMethod = "close")
public RestHighLevelClient client() {
ClientConfiguration clientConfiguration = ClientConfiguration.builder()
.connectedTo(elasticsearchHost)
.usingSsl()
.build();
return RestClients.create(clientConfiguration).rest();
}This all works fine. however when the /actuator/health endpoint of the application is called. It fails and I get a stacktrace from elastic that shows connection refused.
Some debugging showed me that this is because I have two RestClient beans. The second bean is created by the code in RestClientAutoconfiguration below. This is done before my RestClient is created.
This other Restclient is created with the default localhost:9200 configuration and is used for the health check (but not for the actual searching)
/**
* {@link EnableAutoConfiguration Auto-configuration} for Elasticsearch REST clients.
*
* @author Brian Clozel
* @since 2.1.0
*/
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass(RestClient.class)
@EnableConfigurationProperties(RestClientProperties.class)
public class RestClientAutoConfiguration {
@Bean
@ConditionalOnMissingBean
public RestClient restClient(RestClientBuilder builder) {
return builder.build();
}I happen to be running spring boot 2.2.0.M4 (Because of the support for using the highlevel restclient yay)
Keep up the good work and let me know If you need more information
--- Appendix ---
the original stacktrace is
2019-07-09 13:54:19.981 DEBUG 1 --- [io-8080-exec-10] o.s.web.servlet.DispatcherServlet : GET "/actuator/health", parameters={}
2019-07-09 13:54:20.000 WARN 1 --- [io-8080-exec-10] s.b.a.e.ElasticsearchRestHealthIndicator : Elasticsearch health check failed
java.net.ConnectException: Connection refused
at org.elasticsearch.client.RestClient$SyncResponseListener.get(RestClient.java:959) ~[elasticsearch-rest-client-6.7.2.jar!/:6.7.2]
at org.elasticsearch.client.RestClient.performRequest(RestClient.java:233) ~[elasticsearch-rest-client-6.7.2.jar!/:6.7.2]