Skip to content

Deterministic and JVM-independent @Bean registration order within Class-reflected configuration classes [SPR-14505] #19074

Closed
@spring-projects-issues

Description

@spring-projects-issues

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 the Class.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:

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