Fix aggregated application behavior
* After moving some bunch of beans from the `@EnableBinding` to the auto-configuration for proper conditional lifecycle we need to be sure that all those support beans are registered for each child context as it was before after parsing imports on the `@EnableBinding`. This way add `search = SearchStrategy.CURRENT` for all the conditions in the `BindingServiceConfiguration` * Fix `TestSupportBinderConfiguration` to rely only on the `Binder` instance created once in the parent level. This way when we use an aggregated application, only the parent context creates for us a `TestSupportBinder` and all the child contexts reuse it. * Register `BinderFactory` only once in parent ctx
This commit is contained in:
@@ -57,6 +57,8 @@ public class AggregateApplicationTests {
|
||||
.poll(5, TimeUnit.SECONDS));
|
||||
Assert.assertThat(received, notNullValue());
|
||||
Assert.assertTrue(received.getPayload().endsWith("processed"));
|
||||
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Configuration
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.cloud.stream.test.binder;
|
||||
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.cloud.stream.binder.Binder;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -32,6 +33,7 @@ import org.springframework.messaging.MessageChannel;
|
||||
* @author Marius Bogoevici
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnMissingBean(Binder.class)
|
||||
public class TestSupportBinderConfiguration {
|
||||
|
||||
private Binder<MessageChannel, ?, ?> messageChannelBinder = new TestSupportBinder();
|
||||
|
||||
@@ -28,6 +28,7 @@ import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.SearchStrategy;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.cloud.stream.binder.BinderConfiguration;
|
||||
import org.springframework.cloud.stream.binder.BinderFactory;
|
||||
@@ -89,7 +90,7 @@ import org.springframework.util.Assert;
|
||||
@EnableConfigurationProperties({ BindingServiceProperties.class, SpringIntegrationProperties.class })
|
||||
@Import({ContentTypeConfiguration.class, DestinationPublishingMetricsAutoConfiguration.class, SpelExpressionConverterConfiguration.class})
|
||||
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
|
||||
@ConditionalOnBean(BinderTypeRegistry.class)
|
||||
@ConditionalOnBean(value = BinderTypeRegistry.class, search = SearchStrategy.CURRENT)
|
||||
public class BindingServiceConfiguration {
|
||||
|
||||
public static final String STREAM_LISTENER_ANNOTATION_BEAN_POST_PROCESSOR_NAME =
|
||||
@@ -168,7 +169,7 @@ public class BindingServiceConfiguration {
|
||||
}
|
||||
|
||||
@Bean(name = STREAM_LISTENER_ANNOTATION_BEAN_POST_PROCESSOR_NAME)
|
||||
@ConditionalOnMissingBean
|
||||
@ConditionalOnMissingBean(search = SearchStrategy.CURRENT)
|
||||
public static StreamListenerAnnotationBeanPostProcessor streamListenerAnnotationBeanPostProcessor() {
|
||||
return new StreamListenerAnnotationBeanPostProcessor();
|
||||
}
|
||||
@@ -177,7 +178,7 @@ public class BindingServiceConfiguration {
|
||||
// This conditional is intentionally not in an autoconfig (usually a bad idea) because
|
||||
// it is used to detect a BindingService in the parent context (which we know
|
||||
// already exists).
|
||||
@ConditionalOnMissingBean
|
||||
@ConditionalOnMissingBean(search = SearchStrategy.CURRENT)
|
||||
public BindingService bindingService(BindingServiceProperties bindingServiceProperties,
|
||||
BinderFactory binderFactory, TaskScheduler taskScheduler) {
|
||||
return new BindingService(bindingServiceProperties, binderFactory, taskScheduler);
|
||||
|
||||
Reference in New Issue
Block a user