Defensive singleton check for non-registered bean

Closes gh-33286
This commit is contained in:
Juergen Hoeller
2024-07-29 10:47:08 +02:00
parent 5aa38833dd
commit 9d9e621efe
2 changed files with 22 additions and 2 deletions

View File

@@ -308,8 +308,9 @@ public class ScheduledAnnotationBeanPostProcessor
logger.trace(annotatedMethods.size() + " @Scheduled methods processed on bean '" + beanName +
"': " + annotatedMethods);
}
if ((this.beanFactory != null && !this.beanFactory.isSingleton(beanName)) ||
(this.beanFactory instanceof SingletonBeanRegistry sbr && sbr.containsSingleton(beanName))) {
if ((this.beanFactory != null &&
(!this.beanFactory.containsBean(beanName) || !this.beanFactory.isSingleton(beanName)) ||
(this.beanFactory instanceof SingletonBeanRegistry sbr && sbr.containsSingleton(beanName)))) {
// Either a prototype/scoped bean or a FactoryBean with a pre-existing managed singleton
// -> trigger manual cancellation when ContextClosedEvent comes in
this.manualCancellationOnContextClose.add(bean);