Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-15829

Autowire contract is not honored in cases where FactoryBean or @Bean return null

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major
    • Resolution: Complete
    • Affects Version/s: 5.0 RC3
    • Fix Version/s: 5.0 RC4
    • Component/s: Core
    • Labels:
      None
    • Last commented by a User:
      false

      Description

      Configuration below reproduces the issue

      @Autowired
      private FooStrategy foo;
      
      @Bean
      public FooStrategy createFoo() {
      	return null;
      }
      	
      public String doSomethingWithFoo(){
      	return foo.doSomething();;
      }
      

      The bottom line is that the above does NOT result in “Field foo in MyApplication required a bean of type 'FooStrategy' that could not be found.” And instead it results in NPE. But the NPE is not happening during AC initialization, rather during the invocation of any callback to 'foo'.

      Regardless of the reason to return null from the factory method, the main issue IMHO is that @Autowire contract is not followed for this type of scenario.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                juergen.hoeller Juergen Hoeller
                Reporter:
                ozhurakousky Oleg Zhurakousky
                Last updater:
                Juergen Hoeller
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Days since last comment:
                  50 weeks ago