This commit makes sure that no high-level client is auto-configured if
a low-level client is registered as a bean.

See gh-22358
pull/23229/head
Stephane Nicoll 4 years ago
parent aa3c93078e
commit a73b7bb7dd

@ -50,6 +50,7 @@ import org.springframework.util.StringUtils;
*/
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass(RestHighLevelClient.class)
@ConditionalOnMissingBean(RestClient.class)
@EnableConfigurationProperties(ElasticsearchRestClientProperties.class)
public class ElasticsearchRestClientAutoConfiguration {

@ -45,6 +45,7 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
/**
* Tests for {@link ElasticsearchRestClientAutoConfiguration}.
@ -69,6 +70,13 @@ class ElasticsearchRestClientAutoConfigurationTests {
.hasSingleBean(RestHighLevelClient.class));
}
@Test
void configureWhenCustomRestClientShouldBackOff() {
this.contextRunner.withBean("customRestClient", RestClient.class, () -> mock(RestClient.class))
.run((context) -> assertThat(context).doesNotHaveBean(RestHighLevelClient.class)
.hasSingleBean(RestClient.class).hasBean("customRestClient"));
}
@Test
void configureWhenCustomRestHighLevelClientShouldBackOff() {
this.contextRunner.withUserConfiguration(CustomRestHighLevelClientConfiguration.class)

Loading…
Cancel
Save