Skip to content

Autowire contract is not honored in cases where FactoryBean or @Bean return null [SPR-15829] #20384

Closed
@spring-projects-issues

Description

@spring-projects-issues

Oleg Zhurakousky opened SPR-15829 and commented

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.


Affects: 5.0 RC3

Issue Links:

Referenced from: commits 30bd582, b94302b

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions