Merge branch '6.1.x'
This commit is contained in:
commit
7c13d55906
|
|
@ -310,8 +310,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);
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ import java.util.HashMap;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.assertj.core.api.AbstractAssert;
|
||||
|
|
@ -270,6 +271,24 @@ class ScheduledAnnotationBeanPostProcessorTests {
|
|||
assertThat(task.getInitialDelayDuration()).isEqualTo(Duration.ofMillis(2_000L));
|
||||
}
|
||||
|
||||
@Test
|
||||
void oneTimeTaskOnNonRegisteredBean() {
|
||||
BeanDefinition processorDefinition = new RootBeanDefinition(ScheduledAnnotationBeanPostProcessor.class);
|
||||
context.registerBeanDefinition("postProcessor", processorDefinition);
|
||||
context.refresh();
|
||||
|
||||
ScheduledTaskHolder postProcessor = context.getBean("postProcessor", ScheduledTaskHolder.class);
|
||||
assertThat(postProcessor.getScheduledTasks()).hasSize(0);
|
||||
|
||||
Object target = context.getAutowireCapableBeanFactory().createBean(OneTimeTaskBean.class);
|
||||
assertThat(postProcessor.getScheduledTasks()).hasSize(1);
|
||||
@SuppressWarnings("unchecked")
|
||||
Set<Object> manualTasks = (Set<Object>)
|
||||
new DirectFieldAccessor(postProcessor).getPropertyValue("manualCancellationOnContextClose");
|
||||
assertThat(manualTasks).hasSize(1);
|
||||
assertThat(manualTasks).contains(target);
|
||||
}
|
||||
|
||||
@Test
|
||||
void cronTask() {
|
||||
BeanDefinition processorDefinition = new RootBeanDefinition(ScheduledAnnotationBeanPostProcessor.class);
|
||||
|
|
|
|||
Loading…
Reference in New Issue