GH-2283 Fix binder specific 'default' bindings

Resolves #2283
This commit is contained in:
Oleg Zhurakousky
2022-10-04 20:29:10 +02:00
parent b01c804008
commit 053563de54
2 changed files with 11 additions and 6 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2018-2019 the original author or authors.
* Copyright 2018-2022 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.
@@ -30,8 +30,6 @@ import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.integration.support.utils.IntegrationUtils;
/**
* Base implementation of {@link ExtendedBindingProperties}.
*
@@ -90,9 +88,9 @@ public abstract class AbstractExtendedBindingProperties<C, P, T extends BinderSp
.get(this.applicationContext.getEnvironment()),
new PropertySourcesPlaceholdersResolver(
this.applicationContext.getEnvironment()),
IntegrationUtils.getConversionService(
this.applicationContext.getBeanFactory()),
this.applicationContext.getBeanFactory().getConversionService(),
null);
binder.bind(this.getDefaultsPrefix(),
Bindable.ofInstance(extendedBindingPropertiesTarget));
this.bindings.put(binding, extendedBindingPropertiesTarget);

View File

@@ -37,6 +37,7 @@ import org.springframework.cloud.function.context.FunctionCatalog;
import org.springframework.cloud.function.context.catalog.SimpleFunctionRegistry;
import org.springframework.cloud.stream.config.ListenerContainerCustomizer;
import org.springframework.cloud.stream.config.SpelExpressionConverterConfiguration;
import org.springframework.cloud.stream.config.SpelExpressionConverterConfiguration.SpelConverter;
import org.springframework.cloud.stream.reflection.GenericsUtils;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
@@ -46,6 +47,7 @@ import org.springframework.context.ApplicationListener;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.core.convert.support.GenericConversionService;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.MapPropertySource;
import org.springframework.integration.channel.FluxMessageChannel;
@@ -373,7 +375,12 @@ public class DefaultBinderFactory implements BinderFactory, DisposableBean, Appl
ConfigurableApplicationContext initializeBinderContextSimple(String configurationName, Map<String, Object> binderProperties,
BinderType binderType, BinderConfiguration binderConfiguration, boolean refresh) {
AnnotationConfigApplicationContext binderProducingContext = new AnnotationConfigApplicationContext();
if (this.context != null) {
binderProducingContext.getBeanFactory().setConversionService(this.context.getBeanFactory().getConversionService());
GenericConversionService cs = (GenericConversionService) ((GenericApplicationContext) binderProducingContext).getBeanFactory().getConversionService();
SpelConverter spelConverter = new SpelConverter();
cs.addConverter(spelConverter);
}
List<Class> sourceClasses = new ArrayList<>();
sourceClasses.addAll(Arrays.asList(binderType.getConfigurationClasses()));
sourceClasses.addAll(Collections.singletonList(SpelExpressionConverterConfiguration.class));