@Autowired
private FooStrategy foo;
@Bean
public FooStrategy createFoo() {
return null;
}
public String doSomethingWithFoo(){
return foo.doSomething();;
}
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.
Oleg Zhurakousky opened SPR-15829 and commented
Configuration below reproduces the issue
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
@Autowirecontract is not followed for this type of scenario.Affects: 5.0 RC3
Issue Links:
@Lazycollection of optional elements should not crash when no candidates are foundReferenced from: commits 30bd582, b94302b