Skip to content

Deprecate use of several bean factory methods for the same bean in a configuration class #31073

Closed
@snicoll

Description

@snicoll

Consider the following use case:

@Configuration
public class Config {
	
	@Bean(name = "myBean")
	MyBean someBean() { ... }
	
	@Bean(name = "myBean")
	MyBean someBean(MyDependency) { ... }
}

The container accepts an override for myBean as long as it is in the same configuration class to mimic the resolution of the greediest satisfiable constructors for bean factory methods.

Such an arrangement is much better served using Optional or ObjectProvider with a single bean factory method as it makes it explicit that some argument may or may not be available.

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