mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-09-03 04:26:12 +08:00
Auto-configure JsonpMapper even with user-defined transport
Closes gh-36698
This commit is contained in:
parent
803c155e69
commit
c6dc505932
@ -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 @@ import org.springframework.context.annotation.Import;
|
||||
* @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 {
|
||||
|
||||
}
|
||||
|
@ -44,6 +44,12 @@ import org.springframework.context.annotation.Import;
|
||||
*/
|
||||
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 @@ class ElasticsearchClientConfigurations {
|
||||
|
||||
}
|
||||
|
||||
@Import({ JacksonJsonpMapperConfiguration.class, JsonbJsonpMapperConfiguration.class,
|
||||
SimpleJsonpMapperConfiguration.class })
|
||||
@ConditionalOnBean(RestClient.class)
|
||||
@ConditionalOnMissingBean(ElasticsearchTransport.class)
|
||||
static class ElasticsearchTransportConfiguration {
|
||||
|
||||
|
@ -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 @@ import org.springframework.data.elasticsearch.client.elc.ReactiveElasticsearchCl
|
||||
* @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
|
||||
|
@ -154,7 +154,7 @@ class ElasticsearchClientAutoConfigurationTests {
|
||||
static class TransportConfiguration {
|
||||
|
||||
@Bean
|
||||
ElasticsearchTransport customElasticsearchTransport() {
|
||||
ElasticsearchTransport customElasticsearchTransport(JsonpMapper mapper) {
|
||||
return mock(ElasticsearchTransport.class);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user