Skip to content

Commit b2d7867

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 c74cd1f commit b2d7867

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.
@@ -79,7 +79,7 @@ public Object postProcess(Object bean, String beanName, Method method, List<Anno
7979
.resolveAttribute(annotations, AnnotationUtils.VALUE, String.class);
8080
Assert.hasText(channelName, "The channel ('value' attribute of @InboundChannelAdapter) can't be empty.");
8181

82-
MessageSource<?> messageSource = null;
82+
MessageSource<?> messageSource;
8383
try {
8484
messageSource = createMessageSource(bean, beanName, method);
8585
}
@@ -100,10 +100,11 @@ public Object postProcess(Object bean, String beanName, Method method, List<Anno
100100
return adapter;
101101
}
102102

103-
private MessageSource<?> createMessageSource(Object beanArg, String beanName, Method methodArg) {
103+
private MessageSource<?> createMessageSource(Object beanArg, String beanNameArg, Method methodArg) {
104104
MessageSource<?> messageSource = null;
105105
Object bean = beanArg;
106106
Method method = methodArg;
107+
String beanName = beanNameArg;
107108
if (AnnotatedElementUtils.isAnnotated(method, Bean.class.getName())) {
108109
Object target = this.resolveTargetBeanFromMethodWithBeanAnnotation(method);
109110
Class<?> targetClass = target.getClass();
@@ -119,10 +120,12 @@ private MessageSource<?> createMessageSource(Object beanArg, String beanName, Me
119120
else if (target instanceof Supplier<?>) {
120121
method = ReflectionUtils.findMethod(Supplier.class, "get");
121122
bean = target;
123+
beanName += '.' + methodArg.getName();
122124
}
123125
else if (kotlinFunction0Class != null) {
124126
method = ReflectionUtils.findMethod(kotlinFunction0Class, "invoke");
125127
bean = target;
128+
beanName += '.' + methodArg.getName();
126129
}
127130
}
128131
if (messageSource == null) {
@@ -143,7 +146,7 @@ else if (kotlinFunction0Class != null) {
143146
@Override
144147
protected String generateHandlerBeanName(String originalBeanName, Method method) {
145148
return super.generateHandlerBeanName(originalBeanName, method)
146-
.replaceFirst(IntegrationConfigUtils.HANDLER_ALIAS_SUFFIX + "$", ".source");
149+
.replaceFirst(IntegrationConfigUtils.HANDLER_ALIAS_SUFFIX + '$', ".source");
147150
}
148151

149152
@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)