|
30 | 30 | import org.junit.jupiter.api.extension.ExtendWith;
|
31 | 31 |
|
32 | 32 | import org.springframework.beans.factory.config.BeanDefinition;
|
| 33 | +import org.springframework.beans.factory.config.BeanFactoryPostProcessor; |
33 | 34 | import org.springframework.beans.factory.support.BeanDefinitionOverrideException;
|
34 | 35 | import org.springframework.boot.autoconfigure.AutoConfigurations;
|
35 | 36 | import org.springframework.boot.task.SimpleAsyncTaskExecutorBuilder;
|
@@ -239,6 +240,21 @@ void taskExecutorWhenModeIsForceAndHasCustomTaskExecutorWithReservedNameShouldTh
|
239 | 240 | .isInstanceOf(BeanDefinitionOverrideException.class));
|
240 | 241 | }
|
241 | 242 |
|
| 243 | + @Test |
| 244 | + void taskExecutorWhenModeIsForceAndHasCustomBFPPCanRestoreTaskExecutorAlias() { |
| 245 | + this.contextRunner.withBean("customTaskExecutor", Executor.class, SyncTaskExecutor::new) |
| 246 | + .withPropertyValues("spring.task.execution.mode=force") |
| 247 | + .withBean(BeanFactoryPostProcessor.class, |
| 248 | + () -> (beanFactory) -> beanFactory.registerAlias("applicationTaskExecutor", "taskExecutor")) |
| 249 | + .run((context) -> { |
| 250 | + assertThat(context.getBeansOfType(Executor.class)).hasSize(2) |
| 251 | + .containsKeys("customTaskExecutor", "applicationTaskExecutor"); |
| 252 | + assertThat(context).hasBean("taskExecutor"); |
| 253 | + assertThat(context.getBean("taskExecutor")).isSameAs(context.getBean("applicationTaskExecutor")); |
| 254 | + |
| 255 | + }); |
| 256 | + } |
| 257 | + |
242 | 258 | @Test
|
243 | 259 | @EnabledForJreRange(min = JRE.JAVA_21)
|
244 | 260 | void whenVirtualThreadsAreEnabledAndCustomTaskExecutorIsDefinedThenSimpleAsyncTaskExecutorThatUsesVirtualThreadsBacksOff() {
|
@@ -294,18 +310,18 @@ void enableAsyncUsesAutoConfiguredExecutorWhenModeIsForceAndHasCustomTaskExecuto
|
294 | 310 | }
|
295 | 311 |
|
296 | 312 | @Test
|
297 |
| - void enableAsyncUsesCustomExecutorWhenModeIsForceAndHasCustomTaskExecutorWithReservedName() { |
| 313 | + void enableAsyncUsesAutoConfiguredExecutorWhenModeIsForceAndHasCustomTaskExecutorWithReservedName() { |
298 | 314 | this.contextRunner
|
299 | 315 | .withPropertyValues("spring.task.execution.thread-name-prefix=auto-task-",
|
300 | 316 | "spring.task.execution.mode=force")
|
301 | 317 | .withBean("taskExecutor", Executor.class, () -> createCustomAsyncExecutor("custom-task-"))
|
302 | 318 | .withUserConfiguration(AsyncConfiguration.class, TestBean.class)
|
303 | 319 | .run((context) -> {
|
304 |
| - assertThat(context).doesNotHaveBean(AsyncConfigurer.class); |
| 320 | + assertThat(context).hasSingleBean(AsyncConfigurer.class); |
305 | 321 | assertThat(context.getBeansOfType(Executor.class)).hasSize(2);
|
306 | 322 | TestBean bean = context.getBean(TestBean.class);
|
307 | 323 | String text = bean.echo("something").get();
|
308 |
| - assertThat(text).contains("custom-task-").contains("something"); |
| 324 | + assertThat(text).contains("auto-task-").contains("something"); |
309 | 325 | });
|
310 | 326 | }
|
311 | 327 |
|
|
0 commit comments