Skip to content

Commit 9794a9f

Browse files
mjd507cppwfs
authored andcommitted
Revise MBeanExporterHelper reflection logic
Removed reflection logic when getting `channelNames` from bean `$autoCreateChannelCandidates` in favor of `ChannelInitializer.AutoCreateCandidatesCollector.channelNames()` Fixes: #10167 Signed-off-by: Jiandong Ma <[email protected]> address PR comment **Auto-cherry-pick to `6.4.x`** Signed-off-by: Jiandong Ma <[email protected]>
1 parent d43a19b commit 9794a9f

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

spring-integration-jmx/src/main/java/org/springframework/integration/jmx/config/MBeanExporterHelper.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@
2525

2626
import org.springframework.aop.support.AopUtils;
2727
import org.springframework.beans.BeansException;
28-
import org.springframework.beans.DirectFieldAccessor;
2928
import org.springframework.beans.factory.config.DestructionAwareBeanPostProcessor;
3029
import org.springframework.core.Ordered;
3130
import org.springframework.core.annotation.AnnotatedElementUtils;
31+
import org.springframework.integration.config.ChannelInitializer;
32+
import org.springframework.integration.context.IntegrationContextUtils;
3233
import org.springframework.integration.monitor.IntegrationMBeanExporter;
3334
import org.springframework.integration.support.management.IntegrationManagedResource;
3435
import org.springframework.jmx.export.MBeanExporter;
@@ -41,6 +42,7 @@
4142
*
4243
* @author Oleg Zhurakousky
4344
* @author Artem Bilan
45+
* @author Jiandong Ma
4446
*
4547
* @since 2.1
4648
*
@@ -53,10 +55,9 @@ class MBeanExporterHelper implements DestructionAwareBeanPostProcessor, Ordered
5355

5456
@Override
5557
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
56-
if ("$autoCreateChannelCandidates".equals(beanName)) {
57-
@SuppressWarnings("unchecked")
58-
Collection<String> autoCreateChannelCandidatesNames =
59-
(Collection<String>) new DirectFieldAccessor(bean).getPropertyValue("channelNames");
58+
if (IntegrationContextUtils.AUTO_CREATE_CHANNEL_CANDIDATES_BEAN_NAME.equals(beanName)) {
59+
var channelCandidatesCollector = (ChannelInitializer.AutoCreateCandidatesCollector) bean;
60+
Collection<String> autoCreateChannelCandidatesNames = channelCandidatesCollector.channelNames();
6061
this.siBeanNames.addAll(autoCreateChannelCandidatesNames);
6162
if (!this.mBeanExportersForExcludes.isEmpty()) {
6263
autoCreateChannelCandidatesNames
@@ -79,8 +80,7 @@ public Object postProcessAfterInitialization(Object bean, String beanName) throw
7980
this.mBeanExportersForExcludes.forEach(mBeanExporter -> mBeanExporter.addExcludedBean(beanName));
8081
}
8182

82-
if (bean instanceof MBeanExporter && !(bean instanceof IntegrationMBeanExporter)) {
83-
MBeanExporter mBeanExporter = (MBeanExporter) bean;
83+
if (bean instanceof MBeanExporter mBeanExporter && !(bean instanceof IntegrationMBeanExporter)) {
8484
this.mBeanExportersForExcludes.add(mBeanExporter);
8585
this.siBeanNames.forEach(mBeanExporter::addExcludedBean);
8686
}

0 commit comments

Comments
 (0)