Uploaded image for project: 'Spring Integration'
  1. Spring Integration
  2. INT-3765

The ListableBeanFactory.getBeanNamesForType(Class<?> type) causes NoSuchBeanDefinitionException in case of channel auto-creation

    XMLWordPrintable

    Details

      Description

      The case which we have to reproduce is located in the Spring XD META-INF/spring-xd/batch/singlestep-partition-support.xml and represents the partitionHandler which has a reference to the auto-created setHeaderReplyChannelChannel.
      Since INT-3583 we have AggregatorFactoryBean which is FactoryBean and in this case it gets a reference to that partitionHandler.

      From other side JmxIntegrationConfigurationInitializer has a code like this:

      if (beanFactory.getBeanNamesForType(IntegrationMBeanExporter.class).length > 0) {
      

      which is bad for that AggregatorFactoryBean because this method initiate

      • @param allowEagerInit whether to initialize <i>lazy-init singletons</i> and
      • <i>objects created by FactoryBeans</i> (or by factory methods with a
      • "factory-bean" reference) for the type check. Note that FactoryBeans need to be
      • eagerly initialized to determine their type: So be aware that passing in "true"
      • for this flag will initialize FactoryBeans and "factory-bean" references.

      Therefore we end up with:

      Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'setHeaderReplyChannelChannel' is defined
      	at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:698)
      	at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1173)
      	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:282)
      	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
      	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:351)
      	... 84 more
      

      That's because ChannelInitializer hasn't been started yet.

      From one side it is good to have all explicit channel bean definition, but from other side it would be better to revise all ListableBeanFactory.getBeanNamesForType(Class<?> beanClass usage and consider to go ahead with ListableBeanFactory.getBeanNamesForType(Class<?> type, boolean includeNonSingletons, boolean allowEagerInit)

        Attachments

          Activity

            People

            Assignee:
            abilan Artem Bilan
            Reporter:
            abilan Artem Bilan
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: