Description
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:
- Non-helpful NoSuchBeanDefinitionException rather than BeanNotOfRequiredTypeException due to creation order [SPR-14504] #19073 Non-helpful NoSuchBeanDefinitionException rather than BeanNotOfRequiredTypeException due to creation order
- Consistent autowiring behavior for specifically typed injection points against loosely typed @Bean methods [SPR-14960] #19527 Consistent autowiring behavior for specifically typed injection points against loosely typed
@Bean
methods - Doc: Consistent @Profile declarations on overloaded @Bean methods [SPR-15266] #19831 Doc: Consistent
@Profile
declarations on overloaded@Bean
methods - Track bean dependencies for calls between @Bean methods within @Configuration classes [SPR-15069] #19635 Track bean dependencies for calls between
@Bean
methods within@Configuration
classes - Support for @Order on nested configuration classes [SPR-15384] #19947 Support for
@Order
on nested configuration classes