Skip to content

BATCH-3936 StepScope TARGET_NAME_PREFIX scopedTarget #3938

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
*/
public class StepScope extends BatchScopeSupport {

private static final String TARGET_NAME_PREFIX = "stepScopedTarget.";
private static final String TARGET_NAME_PREFIX = "scopedTarget.";

private Log logger = LogFactory.getLog(getClass());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@

package org.springframework.batch.core.configuration.annotation;

import static org.junit.Assert.assertEquals;

import java.util.concurrent.Callable;

import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
Expand All @@ -39,10 +43,6 @@
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.lang.Nullable;

import java.util.concurrent.Callable;

import static org.junit.Assert.assertEquals;

/**
* @author Dave Syer
* @author Michael Minella
Expand Down Expand Up @@ -103,6 +103,19 @@ public void testStepScopeXmlImportUsingNamespace() throws Exception {
assertEquals("STEP", value.call());
}

/**
* @see org.springframework.batch.core.configuration.xml.CoreNamespaceUtils#autoregisterBeansForNamespace
*/
@Test
public void testStepScopeUsingNamespaceAutoregisterBeans() throws Exception {
init(StepScopeConfigurationTestsUsingNamespaceAutoregisterBeans.class);

ISimpleHolder value = (ISimpleHolder) context.getBean("xmlValue");
assertEquals("STEP", value.call());
value = (ISimpleHolder) context.getBean("javaValue");
assertEquals("STEP", value.call());
}

@Test
public void testStepScopeWithProxyTargetClassInjected() throws Exception {
init(StepScopeConfigurationInjectingProxy.class);
Expand Down Expand Up @@ -187,7 +200,11 @@ public String call() throws Exception {
}
}

public static class SimpleHolder {
public static interface ISimpleHolder {
String call() throws Exception;
}

public static class SimpleHolder implements ISimpleHolder {
private final String value;

protected SimpleHolder() {
Expand Down Expand Up @@ -231,6 +248,18 @@ protected SimpleHolder javaValue(@Value("#{stepExecution.stepName}")

}

@Configuration
@ImportResource("org/springframework/batch/core/configuration/annotation/StepScopeConfigurationTestsUsingNamespaceAutoregisterBeans-context.xml")
public static class StepScopeConfigurationTestsUsingNamespaceAutoregisterBeans {

@Bean
@StepScope
protected SimpleHolder javaValue(@Value("#{stepExecution.stepName}") final String value) {
return new SimpleHolder(value);
}

}

@Configuration
@EnableBatchProcessing
public static class StepScopeConfigurationInjectingProxy {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:batch="http://www.springframework.org/schema/batch"
xsi:schemaLocation="
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/batch https://www.springframework.org/schema/batch/spring-batch.xsd">

<bean id="tasklet"
class="org.springframework.batch.core.configuration.annotation.StepScopeConfigurationTests$TaskletSupport" />

<batch:job id="job">
<batch:step id="step1">
<batch:tasklet ref="tasklet" />
</batch:step>
</batch:job>

<bean id="xmlValue"
class="org.springframework.batch.core.configuration.annotation.StepScopeConfigurationTests.SimpleHolder"
scope="step">
<constructor-arg value="#{stepExecution.stepName}" />
</bean>

<batch:job-repository id="jobRepository" />

<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
</beans>