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

Programmatic ObjectProvider retrieval through BeanFactory API [SPR-17075] #21613

Closed
spring-projects-issues opened this issue Jul 23, 2018 · 3 comments
Assignees
Labels
in: core type: enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented Jul 23, 2018

Juergen Hoeller opened SPR-17075 and commented

After several discussions around #21511, #16046 and #13532, it turns out that programmatic retrieval of an ObjectProvider handle - as opposed to it just being obtainable through annotation-driven injection - would significantly enrich functional bean definitions.

So as of 5.1, BeanFactory.getBeanProvider provides a convenient and powerful enough entry point for the time being. Stream access to multiple matching beans is covered in #16046 now; just programmatic bean retrieval with qualifiers is left to #13532 still.


Issue Links:

  • #21511 Support for Supplier as a deferred bean creation
  • #16046 ObjectProvider iterable/stream access for "beans of type" resolution in @Bean methods
  • #16761 Add generics / parameterized type support to ListableBeanFactory getBeanNamesForType/getBeansOfType methods
  • #13532 Convenient programmatic bean retrieval with qualifiers
  • #15860 BeanFactory lacks method for getting bean by type with specified constructor arguments
@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Jul 23, 2018

Dave Syer commented

Can we also have a version of this method that takes a Type or ResolvableType?

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Jul 23, 2018

Juergen Hoeller commented

Good idea! I'll give getBeanProvider(ResolvableType) a try as well; sits nicely next to the existing getBeanNamesForType(ResolvableType)...

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Jul 23, 2018

Juergen Hoeller commented

I've introduced getBeanProvider(Class) and getBeanProvider(ResolvableType), also narrowing getBean(String, Class) and isTypeMatch(String, Class) to a non-null Class argument and enriching NoUniqueBeanDefinitionException with a full ResolvableType.

In addition, ObjectProvider supports iterable/stream access for collection-style resolution of multiple matching beans now: see #16046.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core type: enhancement
Projects
None yet
Development

No branches or pull requests

2 participants