Skip to content

Commit a1f4df8

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 Signed-off-by: Jiandong Ma <[email protected]>
1 parent 49e111d commit a1f4df8

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
@@ -17,7 +17,6 @@
1717
package org.springframework.integration.jmx.config;
1818

1919
import java.util.Collection;
20-
import java.util.Objects;
2120
import java.util.Queue;
2221
import java.util.Set;
2322
import java.util.concurrent.ConcurrentHashMap;
@@ -26,10 +25,11 @@
2625

2726
import org.springframework.aop.support.AopUtils;
2827
import org.springframework.beans.BeansException;
29-
import org.springframework.beans.DirectFieldAccessor;
3028
import org.springframework.beans.factory.config.DestructionAwareBeanPostProcessor;
3129
import org.springframework.core.Ordered;
3230
import org.springframework.core.annotation.AnnotatedElementUtils;
31+
import org.springframework.integration.config.ChannelInitializer;
32+
import org.springframework.integration.context.IntegrationContextUtils;
3333
import org.springframework.integration.monitor.IntegrationMBeanExporter;
3434
import org.springframework.integration.support.management.IntegrationManagedResource;
3535
import org.springframework.jmx.export.MBeanExporter;
@@ -42,6 +42,7 @@
4242
*
4343
* @author Oleg Zhurakousky
4444
* @author Artem Bilan
45+
* @author Jiandong Ma
4546
*
4647
* @since 2.1
4748
*
@@ -54,11 +55,10 @@ class MBeanExporterHelper implements DestructionAwareBeanPostProcessor, Ordered
5455

5556
@Override
5657
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
57-
if ("$autoCreateChannelCandidates".equals(beanName)) {
58-
@SuppressWarnings("unchecked")
59-
Collection<String> autoCreateChannelCandidatesNames =
60-
(Collection<String>) new DirectFieldAccessor(bean).getPropertyValue("channelNames");
61-
this.siBeanNames.addAll(Objects.requireNonNull(autoCreateChannelCandidatesNames));
58+
if (IntegrationContextUtils.AUTO_CREATE_CHANNEL_CANDIDATES_BEAN_NAME.equals(beanName)) {
59+
var channelCandidatesCollector = (ChannelInitializer.AutoCreateCandidatesCollector) bean;
60+
Collection<String> autoCreateChannelCandidatesNames = channelCandidatesCollector.channelNames();
61+
this.siBeanNames.addAll(autoCreateChannelCandidatesNames);
6262
if (!this.mBeanExportersForExcludes.isEmpty()) {
6363
autoCreateChannelCandidatesNames
6464
.stream().

0 commit comments

Comments
 (0)