|
1 | 1 | /*
|
2 |
| - * Copyright 2006-2022 the original author or authors. |
| 2 | + * Copyright 2006-2023 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
16 | 16 |
|
17 | 17 | package org.springframework.batch.core.configuration.annotation;
|
18 | 18 |
|
| 19 | +import java.util.concurrent.Callable; |
| 20 | + |
19 | 21 | import org.junit.jupiter.api.AfterEach;
|
20 | 22 | import org.junit.jupiter.api.BeforeEach;
|
21 | 23 | import org.junit.jupiter.api.Test;
|
| 24 | + |
22 | 25 | import org.springframework.batch.core.StepContribution;
|
23 | 26 | import org.springframework.batch.core.StepExecution;
|
24 | 27 | import org.springframework.batch.core.scope.context.ChunkContext;
|
|
38 | 41 | import org.springframework.context.support.ClassPathXmlApplicationContext;
|
39 | 42 | import org.springframework.lang.Nullable;
|
40 | 43 |
|
41 |
| -import java.util.concurrent.Callable; |
42 |
| - |
43 | 44 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
44 | 45 | import static org.junit.jupiter.api.Assertions.assertThrows;
|
45 | 46 | import static org.junit.jupiter.api.Assertions.assertTrue;
|
@@ -101,6 +102,19 @@ void testStepScopeXmlImportUsingNamespace() throws Exception {
|
101 | 102 | assertEquals("STEP", value.call());
|
102 | 103 | }
|
103 | 104 |
|
| 105 | + /** |
| 106 | + * @see org.springframework.batch.core.configuration.xml.CoreNamespaceUtils#autoregisterBeansForNamespace |
| 107 | + */ |
| 108 | + @Test |
| 109 | + public void testStepScopeUsingNamespaceAutoregisterBeans() throws Exception { |
| 110 | + init(StepScopeConfigurationTestsUsingNamespaceAutoregisterBeans.class); |
| 111 | + |
| 112 | + ISimpleHolder value = (ISimpleHolder) context.getBean("xmlValue"); |
| 113 | + assertEquals("STEP", value.call()); |
| 114 | + value = (ISimpleHolder) context.getBean("javaValue"); |
| 115 | + assertEquals("STEP", value.call()); |
| 116 | + } |
| 117 | + |
104 | 118 | @Test
|
105 | 119 | void testStepScopeWithProxyTargetClassInjected() throws Exception {
|
106 | 120 | init(StepScopeConfigurationInjectingProxy.class);
|
@@ -198,7 +212,13 @@ public String call() throws Exception {
|
198 | 212 |
|
199 | 213 | }
|
200 | 214 |
|
201 |
| - public static class SimpleHolder { |
| 215 | + public static interface ISimpleHolder { |
| 216 | + |
| 217 | + String call() throws Exception; |
| 218 | + |
| 219 | + } |
| 220 | + |
| 221 | + public static class SimpleHolder implements ISimpleHolder { |
202 | 222 |
|
203 | 223 | private final String value;
|
204 | 224 |
|
@@ -243,6 +263,18 @@ protected SimpleHolder javaValue(@Value("#{stepExecution.stepName}") final Strin
|
243 | 263 |
|
244 | 264 | }
|
245 | 265 |
|
| 266 | + @Configuration |
| 267 | + @ImportResource("org/springframework/batch/core/configuration/annotation/StepScopeConfigurationTestsUsingNamespaceAutoregisterBeans-context.xml") |
| 268 | + public static class StepScopeConfigurationTestsUsingNamespaceAutoregisterBeans { |
| 269 | + |
| 270 | + @Bean |
| 271 | + @StepScope |
| 272 | + protected SimpleHolder javaValue(@Value("#{stepExecution.stepName}") final String value) { |
| 273 | + return new SimpleHolder(value); |
| 274 | + } |
| 275 | + |
| 276 | + } |
| 277 | + |
246 | 278 | @Configuration
|
247 | 279 | @EnableBatchProcessing
|
248 | 280 | public static class StepScopeConfigurationInjectingProxy {
|
|
0 commit comments