Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
snicoll opened this issue Aug 18, 2023 · 1 comment
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement

Comments

@snicoll
Copy link
Member

snicoll commented Aug 18, 2023

Consider the following use case:

@Configuration
public class Config {
	
	@Bean(name = "myBean")
	MyBean someBean() { ... }
	
	@Bean(name = "myBean")
	MyBean someBeanWithDep(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.

@snicoll snicoll added the type: enhancement A general enhancement label Aug 18, 2023
@snicoll snicoll added this to the 6.1.x milestone Aug 18, 2023
@jhoeller jhoeller added the in: core Issues in core modules (aop, beans, core, context, expression) label Aug 18, 2023
@jhoeller jhoeller modified the milestones: 6.1.x, 6.1.0-RC1 Aug 18, 2023
@sbrannen sbrannen changed the title Deprecate use of several bean factory method for the same bean in a configuration classs Deprecate use of several bean factory methods for the same bean in a configuration class Aug 18, 2023
@jhoeller jhoeller modified the milestones: 6.1.0-M5, 6.1.0-RC1 Sep 12, 2023
@jhoeller jhoeller modified the milestones: 6.1.0-RC1, 6.2.x Sep 27, 2023
@jhoeller jhoeller modified the milestones: 6.2.x, 6.2.0-M1 Jan 12, 2024
@jhoeller
Copy link
Contributor

Bean method overloading is effectively turned off by default as of 6.0, see #22609. From that perspective, formal deprecation does not seem urgent and might be better off in 7.0.

@jhoeller jhoeller modified the milestones: 6.2.0-M1, General Backlog Feb 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants