Spring Framework
  1. Spring Framework
  2. SPR-9630

Injection of Provider fails for prototype-scoped beans

    Details

    • Last commented by a User:
      false

      Description

      I tried to migrate an existing spring application from 3.0.5 to 3.1.2 and I've noticed a strange bug, that the injection of a provider works the first time but passes subsequent times.

      It seems due the call of DependencyDescriptor.increaseNestingLevel() in the constructor of DependencyObjectFactory. Since the Descriptor is cached, the subsequent calls to BeanFactory.resolveDependency no longer return a Provider, but a reference to the bean.

      I've attached a testcase, which reproduces the problem. The bug seems to be introduced in 3.1.1, according to my tests.

        Issue Links

          Activity

          Hide
          Kilian Matt added a comment -

          Conflicting change was introduced in c55362c3 for SPR-9030

          Show
          Kilian Matt added a comment - Conflicting change was introduced in c55362c3 for SPR-9030
          Hide
          Kilian Matt added a comment - - edited
          Show
          Kilian Matt added a comment - - edited Pull-Request with Patch https://github.com/SpringSource/spring-framework/pull/110
          Hide
          Benjamin Sawary added a comment -

          The solution only works on field-injection. if you're using method-injection, the issue still remains.

          Show
          Benjamin Sawary added a comment - The solution only works on field-injection. if you're using method-injection, the issue still remains.
          Hide
          Juergen Hoeller added a comment -

          Benjamin, are you referring to the solution as shipped in 3.2 M2? According to our unit tests, this seems to work fine for both fields and methods...

          In any case, it would be good to double-check what fails for you there, since we're about to ship 3.1.3 any day now (with the same fix applied).

          Juergen

          Show
          Juergen Hoeller added a comment - Benjamin, are you referring to the solution as shipped in 3.2 M2? According to our unit tests, this seems to work fine for both fields and methods... In any case, it would be good to double-check what fails for you there, since we're about to ship 3.1.3 any day now (with the same fix applied). Juergen
          Hide
          Benjamin Sawary added a comment -

          Hello Juergen,
          I've tested the solution with 3.1.3.SNAPSHOT-BUILD and changed the included unit-test to:

          public static class ObjectFactoryInjectionBean implements Serializable {

          //@Inject
          private Provider<TestBean> testBeanFactory;

          public TestBean getTestBean()

          { return this.testBeanFactory.get(); }

          @Inject
          public void setProvider(Provider<TestBean> testBeanFactory)

          { this.testBeanFactory = testBeanFactory; }

          Benjamin

          Show
          Benjamin Sawary added a comment - Hello Juergen, I've tested the solution with 3.1.3.SNAPSHOT-BUILD and changed the included unit-test to: public static class ObjectFactoryInjectionBean implements Serializable { //@Inject private Provider<TestBean> testBeanFactory; public TestBean getTestBean() { return this.testBeanFactory.get(); } @Inject public void setProvider(Provider<TestBean> testBeanFactory) { this.testBeanFactory = testBeanFactory; } Benjamin
          Hide
          Juergen Hoeller added a comment -

          Thanks, Benjamin. It seems I'm able to reproduce this for the regular bean provider case when using method injection; I've only checked the bean collection case for fields and methods before.

          We'll make sure to have this fixed in time for the 3.1.3 release.

          Juergen

          Show
          Juergen Hoeller added a comment - Thanks, Benjamin. It seems I'm able to reproduce this for the regular bean provider case when using method injection; I've only checked the bean collection case for fields and methods before. We'll make sure to have this fixed in time for the 3.1.3 release. Juergen

            People

            • Assignee:
              Juergen Hoeller
              Reporter:
              Kilian Matt
              Last updater:
              Chris Beams
            • Votes:
              2 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Days since last comment:
                1 year, 26 weeks, 6 days ago