Skip to content

Commit 0ab3958

Browse files
artembilangaryrussell
authored andcommitted
Fix @InChAdapter for several supplier beans
The `InboundChannelAdapterAnnotationPostProcessor` doesn't use a bean method name when it parses a `Supplier` bean and only uses a configuration class name + `get` for method part * Fix `InboundChannelAdapterAnnotationPostProcessor` to also include a bean method name into the final bean name for the `MethodInvokingMessageSource` based on the `Supplier` bean * Modify `ReactiveInboundChannelAdapterTests` to add one more `Supplier` with the `@InboundChannelAdapter` to ensure that configuration is still valid after the fix **Cherry-pick to 5.2.x & 5.1.x**
1 parent 8f6155f commit 0ab3958

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2019 the original author or authors.
2+
* Copyright 2014-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -64,7 +64,7 @@ public Object postProcess(Object bean, String beanName, Method method, List<Anno
6464
MessagingAnnotationUtils.resolveAttribute(annotations, AnnotationUtils.VALUE, String.class);
6565
Assert.hasText(channelName, "The channel ('value' attribute of @InboundChannelAdapter) can't be empty.");
6666

67-
MessageSource<?> messageSource = null;
67+
MessageSource<?> messageSource;
6868
try {
6969
messageSource = createMessageSource(bean, beanName, method);
7070
}
@@ -85,10 +85,11 @@ public Object postProcess(Object bean, String beanName, Method method, List<Anno
8585
return adapter;
8686
}
8787

88-
private MessageSource<?> createMessageSource(Object beanArg, String beanName, Method methodArg) {
88+
private MessageSource<?> createMessageSource(Object beanArg, String beanNameArg, Method methodArg) {
8989
MessageSource<?> messageSource = null;
9090
Object bean = beanArg;
9191
Method method = methodArg;
92+
String beanName = beanNameArg;
9293
if (AnnotatedElementUtils.isAnnotated(method, Bean.class.getName())) {
9394
Object target = resolveTargetBeanFromMethodWithBeanAnnotation(method);
9495
Class<?> targetClass = target.getClass();
@@ -106,10 +107,12 @@ private MessageSource<?> createMessageSource(Object beanArg, String beanName, Me
106107
else if (target instanceof Supplier<?>) {
107108
method = ClassUtils.SUPPLIER_GET_METHOD;
108109
bean = target;
110+
beanName += '.' + methodArg.getName();
109111
}
110112
else if (ClassUtils.KOTLIN_FUNCTION_0_INVOKE_METHOD != null) {
111113
method = ClassUtils.KOTLIN_FUNCTION_0_INVOKE_METHOD;
112114
bean = target;
115+
beanName += '.' + methodArg.getName();
113116
}
114117
}
115118
if (messageSource == null) {
@@ -130,7 +133,7 @@ else if (ClassUtils.KOTLIN_FUNCTION_0_INVOKE_METHOD != null) {
130133
@Override
131134
protected String generateHandlerBeanName(String originalBeanName, Method method) {
132135
return super.generateHandlerBeanName(originalBeanName, method)
133-
.replaceFirst(IntegrationConfigUtils.HANDLER_ALIAS_SUFFIX + "$", ".source");
136+
.replaceFirst(IntegrationConfigUtils.HANDLER_ALIAS_SUFFIX + '$', ".source");
134137
}
135138

136139
@Override

spring-integration-core/src/test/java/org/springframework/integration/endpoint/ReactiveInboundChannelAdapterTests.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,12 @@ public Supplier<Integer> counterMessageSupplier() {
8787
};
8888
}
8989

90+
@Bean
91+
@InboundChannelAdapter(value = "fluxChannel", autoStartup = "false", poller = @Poller(fixedDelay = "100000"))
92+
public Supplier<String> anotherSupplier() {
93+
return () -> "void";
94+
}
95+
9096
@Bean
9197
public MessageChannel fluxChannel() {
9298
return new FluxMessageChannel();

0 commit comments

Comments
 (0)