Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
1 parent
a6d6813
commit fce9a48
Showing
2 changed files
with
52 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
...main/java/org/springframework/batch/core/configuration/annotation/ScopeConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright 2021 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.springframework.batch.core.configuration.annotation; | ||
|
||
import org.springframework.batch.core.scope.JobScope; | ||
import org.springframework.batch.core.scope.StepScope; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
/** | ||
* {@code Configuration} class that provides {@link StepScope} and {@link JobScope}. | ||
* | ||
* @author Dave Syer | ||
*/ | ||
@Configuration(proxyBeanMethods = false) | ||
public class ScopeConfiguration { | ||
|
||
private static StepScope stepScope; | ||
|
||
private static JobScope jobScope; | ||
|
||
static { | ||
jobScope = new JobScope(); | ||
jobScope.setAutoProxy(false); | ||
|
||
stepScope = new StepScope(); | ||
stepScope.setAutoProxy(false); | ||
} | ||
|
||
@Bean | ||
public static StepScope stepScope() { | ||
return stepScope; | ||
} | ||
|
||
@Bean | ||
public static JobScope jobScope() { | ||
return jobScope; | ||
} | ||
} |