mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
Correct conditions on auto-configured JacksonJsonpMapper
See gh-36109 Signed-off-by: Pengfei-Lu <459360594@qq.com>
This commit is contained in:
parent
b3244d19c4
commit
8697d9ddd5
@ -23,7 +23,6 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
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.jackson.JacksonAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.jsonb.JsonbAutoConfiguration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
@ -33,8 +32,7 @@ import org.springframework.context.annotation.Import;
|
||||
* @author Andy Wilkinson
|
||||
* @since 3.0.0
|
||||
*/
|
||||
@AutoConfiguration(after = { JacksonAutoConfiguration.class, JsonbAutoConfiguration.class,
|
||||
ElasticsearchRestClientAutoConfiguration.class })
|
||||
@AutoConfiguration(after = { JsonbAutoConfiguration.class, ElasticsearchRestClientAutoConfiguration.class })
|
||||
@ConditionalOnClass(ElasticsearchClient.class)
|
||||
@Import({ ElasticsearchTransportConfiguration.class, ElasticsearchClientConfiguration.class })
|
||||
public class ElasticsearchClientAutoConfiguration {
|
||||
|
@ -31,6 +31,7 @@ import org.elasticsearch.client.RestClient;
|
||||
|
||||
import org.springframework.beans.factory.ObjectProvider;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@ -44,7 +45,7 @@ import org.springframework.context.annotation.Import;
|
||||
class ElasticsearchClientConfigurations {
|
||||
|
||||
@ConditionalOnMissingBean(JsonpMapper.class)
|
||||
@ConditionalOnBean(ObjectMapper.class)
|
||||
@ConditionalOnClass(ObjectMapper.class)
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
static class JacksonJsonpMapperConfiguration {
|
||||
|
||||
|
@ -30,6 +30,7 @@ import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.jsonb.JsonbAutoConfiguration;
|
||||
import org.springframework.boot.test.context.FilteredClassLoader;
|
||||
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@ -64,14 +65,16 @@ class ElasticsearchClientAutoConfigurationTests {
|
||||
|
||||
@Test
|
||||
void withoutJsonbOrJacksonShouldDefineSimpleMapper() {
|
||||
this.contextRunner.withUserConfiguration(RestClientConfiguration.class)
|
||||
this.contextRunner.withClassLoader(new FilteredClassLoader(ObjectMapper.class))
|
||||
.withUserConfiguration(RestClientConfiguration.class)
|
||||
.run((context) -> assertThat(context).hasSingleBean(JsonpMapper.class)
|
||||
.hasSingleBean(SimpleJsonpMapper.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void withJsonbShouldDefineJsonbMapper() {
|
||||
this.contextRunner.withConfiguration(AutoConfigurations.of(JsonbAutoConfiguration.class))
|
||||
this.contextRunner.withClassLoader(new FilteredClassLoader(ObjectMapper.class))
|
||||
.withConfiguration(AutoConfigurations.of(JsonbAutoConfiguration.class))
|
||||
.withUserConfiguration(RestClientConfiguration.class)
|
||||
.run((context) -> assertThat(context).hasSingleBean(JsonpMapper.class)
|
||||
.hasSingleBean(JsonbJsonpMapper.class));
|
||||
|
Loading…
Reference in New Issue
Block a user