diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/elasticsearch/ElasticsearchClientAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/elasticsearch/ElasticsearchClientAutoConfiguration.java index 64b86ab0e627..f28d32e23997 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/elasticsearch/ElasticsearchClientAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/elasticsearch/ElasticsearchClientAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2022 the original author or authors. + * Copyright 2012-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,12 +17,15 @@ package org.springframework.boot.autoconfigure.elasticsearch; import co.elastic.clients.elasticsearch.ElasticsearchClient; +import org.elasticsearch.client.RestClient; import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.elasticsearch.ElasticsearchClientConfigurations.ElasticsearchClientConfiguration; import org.springframework.boot.autoconfigure.elasticsearch.ElasticsearchClientConfigurations.ElasticsearchTransportConfiguration; +import org.springframework.boot.autoconfigure.elasticsearch.ElasticsearchClientConfigurations.JsonpMapperConfiguration; import org.springframework.boot.autoconfigure.jsonb.JsonbAutoConfiguration; import org.springframework.context.annotation.Import; @@ -33,8 +36,10 @@ * @since 3.0.0 */ @AutoConfiguration(after = { JsonbAutoConfiguration.class, ElasticsearchRestClientAutoConfiguration.class }) +@ConditionalOnBean(RestClient.class) @ConditionalOnClass(ElasticsearchClient.class) -@Import({ ElasticsearchTransportConfiguration.class, ElasticsearchClientConfiguration.class }) +@Import({ JsonpMapperConfiguration.class, ElasticsearchTransportConfiguration.class, + ElasticsearchClientConfiguration.class }) public class ElasticsearchClientAutoConfiguration { } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/elasticsearch/ElasticsearchClientConfigurations.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/elasticsearch/ElasticsearchClientConfigurations.java index 63ec135c01b1..28197797567b 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/elasticsearch/ElasticsearchClientConfigurations.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/elasticsearch/ElasticsearchClientConfigurations.java @@ -44,6 +44,12 @@ */ class ElasticsearchClientConfigurations { + @Import({ JacksonJsonpMapperConfiguration.class, JsonbJsonpMapperConfiguration.class, + SimpleJsonpMapperConfiguration.class }) + static class JsonpMapperConfiguration { + + } + @ConditionalOnMissingBean(JsonpMapper.class) @ConditionalOnClass(ObjectMapper.class) @Configuration(proxyBeanMethods = false) @@ -79,9 +85,6 @@ SimpleJsonpMapper simpleJsonpMapper() { } - @Import({ JacksonJsonpMapperConfiguration.class, JsonbJsonpMapperConfiguration.class, - SimpleJsonpMapperConfiguration.class }) - @ConditionalOnBean(RestClient.class) @ConditionalOnMissingBean(ElasticsearchTransport.class) static class ElasticsearchTransportConfiguration { diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/elasticsearch/ReactiveElasticsearchClientAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/elasticsearch/ReactiveElasticsearchClientAutoConfiguration.java index 25ceac118664..d02c60ef365f 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/elasticsearch/ReactiveElasticsearchClientAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/elasticsearch/ReactiveElasticsearchClientAutoConfiguration.java @@ -17,6 +17,7 @@ package org.springframework.boot.autoconfigure.elasticsearch; import co.elastic.clients.transport.ElasticsearchTransport; +import org.elasticsearch.client.RestClient; import reactor.core.publisher.Mono; import org.springframework.boot.autoconfigure.AutoConfiguration; @@ -37,9 +38,11 @@ * @since 3.0.0 */ @AutoConfiguration(after = ElasticsearchClientAutoConfiguration.class) +@ConditionalOnBean(RestClient.class) @ConditionalOnClass({ ReactiveElasticsearchClient.class, ElasticsearchTransport.class, Mono.class }) @EnableConfigurationProperties(ElasticsearchProperties.class) -@Import(ElasticsearchClientConfigurations.ElasticsearchTransportConfiguration.class) +@Import({ ElasticsearchClientConfigurations.JsonpMapperConfiguration.class, + ElasticsearchClientConfigurations.ElasticsearchTransportConfiguration.class }) public class ReactiveElasticsearchClientAutoConfiguration { @Bean diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/elasticsearch/ElasticsearchClientAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/elasticsearch/ElasticsearchClientAutoConfigurationTests.java index 3dbaaa80100e..1f1d84333dcc 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/elasticsearch/ElasticsearchClientAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/elasticsearch/ElasticsearchClientAutoConfigurationTests.java @@ -154,7 +154,7 @@ JsonpMapper customJsonpMapper() { static class TransportConfiguration { @Bean - ElasticsearchTransport customElasticsearchTransport() { + ElasticsearchTransport customElasticsearchTransport(JsonpMapper mapper) { return mock(ElasticsearchTransport.class); }