Skip to content

Commit fce9a48

Browse files
hpoettkerfmbenhassine
authored andcommitted
Make ScopeConfiguration publicly accessible
When using a hierarchy of Spring contexts, custom scopes are not visible in child contexts. With this change, it is now possible for users to import the configuration class into child contexts and use job and step scope within them. Issue #3958
1 parent a6d6813 commit fce9a48

File tree

2 files changed

+52
-34
lines changed

2 files changed

+52
-34
lines changed

spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/AbstractBatchConfiguration.java

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
import org.springframework.batch.core.explore.JobExplorer;
2525
import org.springframework.batch.core.launch.JobLauncher;
2626
import org.springframework.batch.core.repository.JobRepository;
27-
import org.springframework.batch.core.scope.JobScope;
28-
import org.springframework.batch.core.scope.StepScope;
2927
import org.springframework.beans.factory.InitializingBean;
3028
import org.springframework.beans.factory.annotation.Autowired;
3129
import org.springframework.context.annotation.Bean;
@@ -123,35 +121,3 @@ protected BatchConfigurer getConfigurer(Collection<BatchConfigurer> configurers)
123121
}
124122

125123
}
126-
127-
/**
128-
* Extract job/step scope configuration into a separate unit.
129-
*
130-
* @author Dave Syer
131-
*
132-
*/
133-
@Configuration(proxyBeanMethods = false)
134-
class ScopeConfiguration {
135-
136-
private static StepScope stepScope;
137-
138-
private static JobScope jobScope;
139-
140-
static {
141-
jobScope = new JobScope();
142-
jobScope.setAutoProxy(false);
143-
144-
stepScope = new StepScope();
145-
stepScope.setAutoProxy(false);
146-
}
147-
148-
@Bean
149-
public static StepScope stepScope() {
150-
return stepScope;
151-
}
152-
153-
@Bean
154-
public static JobScope jobScope() {
155-
return jobScope;
156-
}
157-
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright 2021 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.batch.core.configuration.annotation;
17+
18+
import org.springframework.batch.core.scope.JobScope;
19+
import org.springframework.batch.core.scope.StepScope;
20+
import org.springframework.context.annotation.Bean;
21+
import org.springframework.context.annotation.Configuration;
22+
23+
/**
24+
* {@code Configuration} class that provides {@link StepScope} and {@link JobScope}.
25+
*
26+
* @author Dave Syer
27+
*/
28+
@Configuration(proxyBeanMethods = false)
29+
public class ScopeConfiguration {
30+
31+
private static StepScope stepScope;
32+
33+
private static JobScope jobScope;
34+
35+
static {
36+
jobScope = new JobScope();
37+
jobScope.setAutoProxy(false);
38+
39+
stepScope = new StepScope();
40+
stepScope.setAutoProxy(false);
41+
}
42+
43+
@Bean
44+
public static StepScope stepScope() {
45+
return stepScope;
46+
}
47+
48+
@Bean
49+
public static JobScope jobScope() {
50+
return jobScope;
51+
}
52+
}

0 commit comments

Comments
 (0)