Fix IntegrationMBeanExporter logic for endpoints

Related to https://stackoverflow.com/questions/72851234/error-in-startup-application-when-using-serviceactivator-in-spring-cloud-stream

The `MessagingAnnotationPostProcessor` register an `endpoint` bean for Messaging Annotation on POJO methods.
The `IntegrationMBeanExporter` post-process such a bean and registers respective MBean.
It does this not in optimal way scanning all the `IntegrationConsumer` beans for requested `MessageHandler`
which may cause a `BeanCurrentlyInCreationException`.

* Rework the logic of the `IntegrationMBeanExporter.postProcessAbstractEndpoint()` to propagate provided endpoint
for the monitor registration to bypass application context scanning for matched name.
* Swap `equals()` for `monitor` since an `extractTarget()` may return `null`
* Some other code clean in the `IntegrationMBeanExporter`
* Change one of the `@ServiceActivator` in the configuration for the `ScatterGatherHandlerIntegrationTests`
to POJO method.
However, this didn't fail for me with original code unlike in the sample application provided in the mentioned SO thread.

**Cherry-pick to `main`**
This commit is contained in:
Artem Bilan
2022-07-07 15:30:43 -04:00
committed by Gary Russell
parent 733eb40e7b
commit 4a55fa3188
2 changed files with 39 additions and 45 deletions

View File

@@ -333,21 +333,9 @@ public class ScatterGatherHandlerIntegrationTests {
return new DirectChannel();
}
@Bean
@ServiceActivator(inputChannel = "serviceChannel2")
public MessageHandler service2() {
return new AbstractReplyProducingMessageHandler() {
{
setOutputChannel(gatherChannel());
}
@Override
protected Object handleRequestMessage(Message<?> requestMessage) {
return Math.random();
}
};
@ServiceActivator(inputChannel = "serviceChannel2", outputChannel = "gatherChannel")
public double service2() {
return Math.random();
}
}