From a1cf665f98a72780c42e631b5a0b76b381b50963 Mon Sep 17 00:00:00 2001 From: "P.J. Meisch" Date: Mon, 29 Jul 2019 08:01:36 +0200 Subject: [PATCH 1/2] Allow for custom EntityMapper bean See gh-17661 --- .../ElasticsearchDataConfiguration.java | 2 ++ ...asticsearchDataAutoConfigurationTests.java | 22 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchDataConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchDataConfiguration.java index f3647113cd..644c6acc43 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchDataConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchDataConfiguration.java @@ -48,6 +48,7 @@ import org.springframework.web.reactive.function.client.WebClient; * their order of execution. * * @author Brian Clozel + * @author Peter-Josef Meisch */ abstract class ElasticsearchDataConfiguration { @@ -67,6 +68,7 @@ abstract class ElasticsearchDataConfiguration { } @Bean + @ConditionalOnMissingBean EntityMapper entityMapper(SimpleElasticsearchMappingContext mappingContext) { return new DefaultEntityMapper(mappingContext); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchDataAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchDataAutoConfigurationTests.java index f22c9c23c5..caa06530db 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchDataAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchDataAutoConfigurationTests.java @@ -28,6 +28,7 @@ import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.boot.testsupport.testcontainers.DisabledWithoutDockerTestcontainers; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.data.elasticsearch.core.ElasticsearchEntityMapper; import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate; import org.springframework.data.elasticsearch.core.ElasticsearchTemplate; import org.springframework.data.elasticsearch.core.EntityMapper; @@ -90,6 +91,11 @@ class ElasticsearchDataAutoConfigurationTests { .hasSingleBean(ElasticsearchConverter.class)); } + @Test + void defaultEntityMapperRegistered() { + this.contextRunner.run((context) -> assertThat(context).hasSingleBean(EntityMapper.class)); + } + @Test void customTransportTemplateShouldBeUsed() { this.contextRunner.withUserConfiguration(CustomTransportTemplate.class).run((context) -> assertThat(context) @@ -109,6 +115,12 @@ class ElasticsearchDataAutoConfigurationTests { .contains("reactiveElasticsearchTemplate")); } + @Test + void customEntityMapperShouldeBeUsed() { + this.contextRunner.withUserConfiguration(CustomEntityMapper.class).run((context) -> assertThat(context) + .getBeanNames(EntityMapper.class).containsExactly("elasticsearchEntityMapper")); + } + @Configuration(proxyBeanMethods = false) static class CustomTransportTemplate { @@ -139,4 +151,14 @@ class ElasticsearchDataAutoConfigurationTests { } + @Configuration(proxyBeanMethods = false) + static class CustomEntityMapper { + + @Bean + EntityMapper elasticsearchEntityMapper() { + return mock(ElasticsearchEntityMapper.class); + } + + } + } From 44a0afcec367ea44e6394a692f211f91b049dfe4 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Wed, 31 Jul 2019 10:46:29 +0200 Subject: [PATCH 2/2] Polish "Allow for custom EntityMapper bean" See gh-17661 --- .../data/elasticsearch/ElasticsearchDataConfiguration.java | 1 - .../elasticsearch/ElasticsearchDataAutoConfigurationTests.java | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchDataConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchDataConfiguration.java index 644c6acc43..91f2e84111 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchDataConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchDataConfiguration.java @@ -48,7 +48,6 @@ import org.springframework.web.reactive.function.client.WebClient; * their order of execution. * * @author Brian Clozel - * @author Peter-Josef Meisch */ abstract class ElasticsearchDataConfiguration { diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchDataAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchDataAutoConfigurationTests.java index caa06530db..bcdf84dfc6 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchDataAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchDataAutoConfigurationTests.java @@ -45,6 +45,7 @@ import static org.mockito.Mockito.mock; * @author Phillip Webb * @author Artur Konczak * @author Brian Clozel + * @author Peter-Josef Meisch */ @DisabledWithoutDockerTestcontainers class ElasticsearchDataAutoConfigurationTests {