Allow for custom EntityMapper bean
See gh-17661
This commit is contained in:
committed by
Stephane Nicoll
parent
e419aab00f
commit
a1cf665f98
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user