See https://github.com/spring-projects/spring-boot/issues/38473 for background.

We'd basically like a new method where this call passes in a allowFactoryBeanInit parameter.

Comment From: jhoeller

Since that affects Boot 3.1.x, I assume you expect such a method to become available in Framework 6.0.x?

Comment From: jhoeller

Since getBeanNamesForAnnotation is effectively just a loop around findAnnotationOnBean, this can also be quite easily done externally: Take getBeanNamesIterator() and then call the allowFactoryBeanInit-enabled findAnnotationOnBean variant from there. Alternatively, you could keep doing separate beanDefinitionNames+singletonNames iteration as in the recent commit.

Since we would not only have to add a corresponding getBeanNamesForAnnotation variant but also an overloaded getBeansWithAnnotation variant for completeness, I'm inclined to suggest the external iteration approach instead. Not only for Boot 3.1.x but also for Boot 3.2 going forward.