Defer Messaging annotations process (#2769)

* Defer Messaging annotations process

The `AbstractMethodAnnotationPostProcessor` and its implementations
have a `beanFactory.getBean()` call for the `@Bean` methods with
Messaging annotations.
This is done, actually, from the
`MessagingAnnotationPostProcessor.postProcessAfterInitialization()`
which might be still too early in some scenarios, like Spring Cloud Feign
with its child application contexts being initialized from the
`FeignClientFactoryBean`, causing a `BeanCurrentlyInCreationException`

See https://stackoverflow.com/questions/54887963/beancurrentlyincreationexception-when-using-spring-integration-with-spring-cloud

* Implement a `SmartInitializingSingleton` for the `MessagingAnnotationPostProcessor`
and gather `Runnable` wrappers for newly introduced `postProcessMethodAndRegisterEndpointIfAny()`
to be called later in the `afterSingletonsInstantiated()` when context is
still in the initialization phase.
All runtime-registered beans are going to be processed normally from the
regular `postProcessAfterInitialization()`

**Cherry-pick to 5.1.x**

* * Fix unused imports in the `MessagingAnnotationsWithBeanAnnotationTests`

* * Fix `IntegrationEndpointsInitializer` in the testing framework to handle
all the possible `AbstractEndpoint` beans registration.
See its JavaDocs for more info
* Fix `AbstractCorrelatingMessageHandlerParser` and
`AbstractConsumerEndpointParser` to use bean names for `outputChannel`
and `discardChannel` instead of bean references.
Since `MessagingAnnotationPostProcessor` now registers endpoints and
beans for channels much later, than parsers, we can't rely on bean
references any more there.
* Fixes for failing tests which expected `outputChannel/discardChannel`
bean references, when it is already just their names for late binding.
* Apply some code style polishing for the affected classes.
* Add `@Nullable` for `MessageSelector` parameter in the `QueueChannel.purge()`
This commit is contained in:
Artem Bilan
2019-03-01 10:26:05 -05:00
committed by Gary Russell
parent 4365eaef6d
commit 3657d05596
27 changed files with 345 additions and 253 deletions

View File

@@ -65,12 +65,12 @@ public class FileSplitterParserTests {
assertThat(TestUtils.getPropertyValue(this.splitter, "applySequence", Boolean.class)).isTrue();
assertThat(TestUtils.getPropertyValue(this.splitter, "charset")).isEqualTo(Charset.forName("UTF-8"));
assertThat(TestUtils.getPropertyValue(this.splitter, "messagingTemplate.sendTimeout")).isEqualTo(5L);
assertThat(TestUtils.getPropertyValue(this.splitter, "outputChannel")).isEqualTo(this.out);
assertThat(TestUtils.getPropertyValue(this.splitter, "order")).isEqualTo(2);
assertThat(TestUtils.getPropertyValue(this.splitter, "firstLineHeaderName")).isEqualTo("foo");
assertThat(TestUtils.getPropertyValue(this.fullBoat, "inputChannel")).isEqualTo(this.in);
assertThat(TestUtils.getPropertyValue(this.fullBoat, "autoStartup", Boolean.class)).isFalse();
assertThat(TestUtils.getPropertyValue(this.fullBoat, "phase")).isEqualTo(1);
assertThat(this.splitter.getOutputChannel()).isSameAs(this.out);
assertThat(this.splitter.getOrder()).isEqualTo(2);
assertThat(this.fullBoat.getInputChannel()).isSameAs(this.in);
assertThat(this.fullBoat.isAutoStartup()).isFalse();
assertThat(this.fullBoat.getPhase()).isEqualTo(1);
}
}