Use BeanInstanceSupplier with matching arguments#36949
Open
yeomin4242 wants to merge 1 commit into
Open
Conversation
BeanFactory#getBean(..., args) previously skipped instance suppliers whenever explicit arguments were provided. In AOT/native mode, this could make a prototype bean with runtime constructor arguments use a different instantiation path and miss generated post-processing. Allow BeanInstanceSupplier to opt in when the explicit arguments exactly match the selected constructor or factory method, while keeping the regular bean factory path for other argument shapes. Closes spring-projectsgh-36649 Signed-off-by: YeongJae Min <whereismysejong@naver.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
BeanFactory#getBean(..., args)currently skips anInstanceSupplierwhenever explicit arguments are provided. In AOT/native mode this can make a prototype bean with runtime constructor arguments use a different instantiation path, so AOT-generated post-processing such as field autowiring is not applied.This PR lets
BeanInstanceSupplieropt in when the explicit arguments match the AOT-selected constructor or factory method. Other cases continue through the regular bean factory path, preserving dynamic constructor resolution for argument shapes that cannot be handled safely by the generated supplier.Regression tests cover the original prototype bean scenario with field autowiring, explicit argument handling in
BeanInstanceSupplier, and fallback behavior for unsupported argument shapes.Closes gh-36649