Skip to content

Commit

Permalink
GH-8654: Fix bean deps for messaging annotations (#8657)
Browse files Browse the repository at this point in the history
Fixes #8654

Spring Framework has an ability to start dependant beans automatically
when we start the current one.

The `AbstractMethodAnnotationPostProcessor` is missing a bean dependency
registration causing errors in target applications when Messaging Annotations configuration is used.

* Add `registerDependentBean()` into an `AbstractMethodAnnotationPostProcessor` when we generate
and register a `ConsumerEndpointFactoryBean`
* Change one of the `ClientManagerBackToBackTests` configuration to rely on a `@ServiceActivator`
for `Mqttv5PahoMessageHandler` bean to ensure that change in the `AbstractMethodAnnotationPostProcessor`
has a proper effect

**Cherry-pick to `6.1.x` & `6.0.x`**
  • Loading branch information
artembilan committed Jun 26, 2023
1 parent 070c1c6 commit af95829
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
Expand Up @@ -270,6 +270,7 @@ else if (reactive != null) {
String endpointBeanName =
generateHandlerBeanName(beanName, mergedAnnotations)
.replaceFirst("\\.(handler|source)$", "");
this.beanFactory.registerDependentBean(beanName, endpointBeanName);
this.definitionRegistry.registerBeanDefinition(endpointBeanName, endpointBeanDefinition);
}

Expand Down
Expand Up @@ -28,6 +28,7 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.EventListener;
import org.springframework.integration.annotation.ServiceActivator;
import org.springframework.integration.config.EnableIntegration;
import org.springframework.integration.dsl.IntegrationFlow;
import org.springframework.integration.mqtt.core.Mqttv3ClientManager;
Expand Down Expand Up @@ -195,8 +196,9 @@ public Mqttv5ClientManager mqttv5ClientManager() {
}

@Bean
public IntegrationFlow mqttOutFlow(Mqttv5ClientManager mqttv5ClientManager) {
return f -> f.handle(new Mqttv5PahoMessageHandler(mqttv5ClientManager));
@ServiceActivator(inputChannel = "mqttOutFlow.input")
public Mqttv5PahoMessageHandler mqttv5PahoMessageHandler(Mqttv5ClientManager mqttv5ClientManager) {
return new Mqttv5PahoMessageHandler(mqttv5ClientManager);
}

@Bean
Expand Down

0 comments on commit af95829

Please sign in to comment.