-
Notifications
You must be signed in to change notification settings - Fork 38.4k
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
Deterministic and JVM-independent @Bean registration order within Class-reflected configuration classes [SPR-14505] #19074
Comments
Juergen Hoeller commented The best compromise from my perspective: Let's preserve the original declaration order that we get from the ASM variant and simply accomplish it on a best-effort basis for the For configuration classes with more than one Given the low impact of only trying this for selected configuration classes and defensively falling back if not possible, and all of this only mattering for |
Juergen Hoeller commented Artem Bilan, good catch there with expectations that As for scenarios like yours, for maximum efficiency, I'd recommend a conditional downcast: If it is |
Artem Bilan commented Thank you very much for all your wisdom and for this fix in particular! As for your idea to restore compatibility. Well, I don't think so. This is a matter of Framework code, not sure that it would be so critical for target applications. Yes, sure thing about your "maximum efficiency" suggestion. No reason to load class one more time if that is done by the |
Juergen Hoeller commented That efficiency of reusing pre-loaded |
Juergen Hoeller opened SPR-14505 and commented
As noted in #19073, the JVM's
Class.getDeclaredMethods()
may return the methods in any order... not just dependent on the bytecode but even dependent on the particular JVM run, which means it might differ on re-execution of the very same classes on the very same JVM.As a consequence, we should consider some deterministic order that we can enforce within the framework, e.g. sorting the
@Bean
methods within each configuration class before registering bean definitions for them.However, we have two modes of registration: ASM-based, automatically applied for bean definitions registered with class name (and therefore also for classpath scanning); and reflection-based, automatically applied for bean definitions registered with a pre-resolved
Class
. ASM-based parsing follows source-code declaration order, while reflection-based parsing follows theClass.getDeclaredMethods()
order of the particular JVM. While the latter would benefit from a custom deterministic order that we're enforcing, that'd be a step backwards for our ASM mode since source-code declaration order is arguably ideal there.Affects: 4.3.1
Issue Links:
@Bean
methods@Profile
declarations on overloaded@Bean
methods@Bean
methods within@Configuration
classes@Order
on nested configuration classesThe text was updated successfully, but these errors were encountered: