2525
2626import org .springframework .aop .support .AopUtils ;
2727import org .springframework .beans .BeansException ;
28- import org .springframework .beans .DirectFieldAccessor ;
2928import org .springframework .beans .factory .config .DestructionAwareBeanPostProcessor ;
3029import org .springframework .core .Ordered ;
3130import org .springframework .core .annotation .AnnotatedElementUtils ;
31+ import org .springframework .integration .config .ChannelInitializer ;
32+ import org .springframework .integration .context .IntegrationContextUtils ;
3233import org .springframework .integration .monitor .IntegrationMBeanExporter ;
3334import org .springframework .integration .support .management .IntegrationManagedResource ;
3435import org .springframework .jmx .export .MBeanExporter ;
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