Spring Framework
  1. Spring Framework
  2. SPR-8954

BeanFactory does not return FactoryBeans in case the are looked up by type and type prediction is used

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Complete
    • Affects Version/s: 3.0.6, 3.1 GA
    • Fix Version/s: 3.1.1
    • Component/s: Core
    • Labels:
      None
    • Last commented by a User:
      false

      Description

      Assume the following FactoryBean implementation:

      public MyFactoryBean implements FactoryBean<Object>, AnInterface { ... }
      

      Now assume we have a SmartInstantiationAwareBeanPostProcessor registered that does return an arbitrary different type from a call to predictBeanType(...). If you now call BeanFactory.getBeansOfType(AnInterface.class) the registered bean instance will not be returned as the type check is done against the type the factory produces in the first place. If that fails the actual bean type is checked against the given type if the bean definition is considered a factory bean.

      AbstractBeanFactory.isFactoryBean(...) now inspects the predicted bean type and thus does not consider the bean as factory bean. Shouldn't this method check the actual bean type as well or even instead? The current implementation pretty much disables the bean definition being discovered as factory bean as soon as you predict the bean type.

        Issue Links

          Activity

          Hide
          Chris Beams added a comment -

          Pull request submitted at https://github.com/SpringSource/spring-framework/pull/16; Juergen asked to review.

          Show
          Chris Beams added a comment - Pull request submitted at https://github.com/SpringSource/spring-framework/pull/16 ; Juergen asked to review.
          Hide
          Juergen Hoeller added a comment -

          Looks good. Merged into 3.1.x branch now.

          Show
          Juergen Hoeller added a comment - Looks good. Merged into 3.1.x branch now.
          Hide
          Oliver Gierke added a comment - - edited

          In case there's a 3.0.8 coming, could this be back ported? I have some tickets open for Spring Data components that actually boil down to this issue and people might not be able to upgrade to a 3.1.1 yet.

          Show
          Oliver Gierke added a comment - - edited In case there's a 3.0.8 coming, could this be back ported? I have some tickets open for Spring Data components that actually boil down to this issue and people might not be able to upgrade to a 3.1.1 yet.
          Hide
          Jim Shi added a comment -

          I've upgrade to Spring 3.1.1 which include spring-core, spring-beans, spring-context, spring-context-support, spring-asm and spring-aopm, but it still not resolve the issue on Spring Data DATAJPA-167.
          The collection from BeanFactoryUtils.beansOfTypeIncludingAncestors(RepositoryFactoryInformation.class) is still empty.

          Show
          Jim Shi added a comment - I've upgrade to Spring 3.1.1 which include spring-core, spring-beans, spring-context, spring-context-support, spring-asm and spring-aopm, but it still not resolve the issue on Spring Data DATAJPA-167 . The collection from BeanFactoryUtils.beansOfTypeIncludingAncestors(RepositoryFactoryInformation.class) is still empty.
          Hide
          Chris Beams added a comment -

          Hi @Jim, I'd recommend opening another issue and submitting a reproduction project to ensure this doesn't slip through the cracks. @Oliver, perhaps you have something to add here?

          Show
          Chris Beams added a comment - Hi @Jim, I'd recommend opening another issue and submitting a reproduction project to ensure this doesn't slip through the cracks. @Oliver, perhaps you have something to add here?
          Hide
          Oliver Gierke added a comment -

          I added a testcase and commented back on the ticket in SD JPA. Wanted to come up with a more local test case for DomainClassConverter but stumbled over the fact that the fix doesn't seem to apply to JavaConfig. Coming up with an XML based test case in SD Commons is quite hard as we don't have a real namespace there (as it's the concrete store specific modules providing it). I'll have another look trying to see what I can do.

          Show
          Oliver Gierke added a comment - I added a testcase and commented back on the ticket in SD JPA. Wanted to come up with a more local test case for DomainClassConverter but stumbled over the fact that the fix doesn't seem to apply to JavaConfig. Coming up with an XML based test case in SD Commons is quite hard as we don't have a real namespace there (as it's the concrete store specific modules providing it). I'll have another look trying to see what I can do.
          Hide
          Chris Beams added a comment -

          Ok, just submit a new issue if appropriate.

          Show
          Chris Beams added a comment - Ok, just submit a new issue if appropriate.

            People

            • Assignee:
              Chris Beams
              Reporter:
              Oliver Gierke
              Last updater:
              Oliver Gierke
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Days since last comment:
                2 years, 7 weeks, 2 days ago