Skip to content

Commit af95829

Browse files
authored
GH-8654: Fix bean deps for messaging annotations (#8657)
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`**
1 parent 070c1c6 commit af95829

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

spring-integration-core/src/main/java/org/springframework/integration/config/AbstractMethodAnnotationPostProcessor.java

+1
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ else if (reactive != null) {
270270
String endpointBeanName =
271271
generateHandlerBeanName(beanName, mergedAnnotations)
272272
.replaceFirst("\\.(handler|source)$", "");
273+
this.beanFactory.registerDependentBean(beanName, endpointBeanName);
273274
this.definitionRegistry.registerBeanDefinition(endpointBeanName, endpointBeanDefinition);
274275
}
275276

spring-integration-mqtt/src/test/java/org/springframework/integration/mqtt/ClientManagerBackToBackTests.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.springframework.context.annotation.Bean;
2929
import org.springframework.context.annotation.Configuration;
3030
import org.springframework.context.event.EventListener;
31+
import org.springframework.integration.annotation.ServiceActivator;
3132
import org.springframework.integration.config.EnableIntegration;
3233
import org.springframework.integration.dsl.IntegrationFlow;
3334
import org.springframework.integration.mqtt.core.Mqttv3ClientManager;
@@ -195,8 +196,9 @@ public Mqttv5ClientManager mqttv5ClientManager() {
195196
}
196197

197198
@Bean
198-
public IntegrationFlow mqttOutFlow(Mqttv5ClientManager mqttv5ClientManager) {
199-
return f -> f.handle(new Mqttv5PahoMessageHandler(mqttv5ClientManager));
199+
@ServiceActivator(inputChannel = "mqttOutFlow.input")
200+
public Mqttv5PahoMessageHandler mqttv5PahoMessageHandler(Mqttv5ClientManager mqttv5ClientManager) {
201+
return new Mqttv5PahoMessageHandler(mqttv5ClientManager);
200202
}
201203

202204
@Bean

0 commit comments

Comments
 (0)