diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/jsr/configuration/xml/JsrBeanDefinitionDocumentReader.java b/spring-batch-core/src/main/java/org/springframework/batch/core/jsr/configuration/xml/JsrBeanDefinitionDocumentReader.java index 80f52bf52..ae2fc54f5 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/jsr/configuration/xml/JsrBeanDefinitionDocumentReader.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/jsr/configuration/xml/JsrBeanDefinitionDocumentReader.java @@ -15,11 +15,13 @@ */ package org.springframework.batch.core.jsr.configuration.xml; +import java.util.Enumeration; import java.util.HashMap; import java.util.Map; import java.util.Properties; import java.util.regex.Matcher; import java.util.regex.Pattern; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.batch.core.jsr.configuration.support.JsrExpressionParser; @@ -121,7 +123,12 @@ public class JsrBeanDefinitionDocumentReader extends DefaultBeanDefinitionDocume return new Properties(); } - jobParameters.putAll(properties); + Enumeration propertyNames = properties.propertyNames(); + + while(propertyNames.hasMoreElements()) { + String curName = (String) propertyNames.nextElement(); + jobParameters.put(curName, properties.getProperty(curName)); + } } return jobParameters; diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/jsr/launch/JsrJobOperator.java b/spring-batch-core/src/main/java/org/springframework/batch/core/jsr/launch/JsrJobOperator.java index 6932fe566..fe26b4701 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/jsr/launch/JsrJobOperator.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/jsr/launch/JsrJobOperator.java @@ -18,6 +18,7 @@ package org.springframework.batch.core.jsr.launch; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.Enumeration; import java.util.HashSet; import java.util.List; import java.util.Map; @@ -426,7 +427,6 @@ public class JsrJobOperator implements JobOperator, InitializingBean { throws JobExecutionAlreadyCompleteException, NoSuchJobExecutionException, JobExecutionNotMostRecentException, JobRestartException, JobSecurityException { - org.springframework.batch.core.JobExecution previousJobExecution = jobExplorer.getJobExecution(executionId); if (previousJobExecution == null) { @@ -556,8 +556,13 @@ public class JsrJobOperator implements JobOperator, InitializingBean { } } - if (params != null && !params.isEmpty()) { - jobRestartProperties.putAll(params); + if (params != null) { + Enumeration propertyNames = params.propertyNames(); + + while(propertyNames.hasMoreElements()) { + String curName = (String) propertyNames.nextElement(); + jobRestartProperties.setProperty(curName, params.getProperty(curName)); + } } return jobRestartProperties; diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/launch/JsrJobOperatorTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/launch/JsrJobOperatorTests.java index 32f2ef788..52aafee51 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/launch/JsrJobOperatorTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/launch/JsrJobOperatorTests.java @@ -468,6 +468,24 @@ public class JsrJobOperatorTests { assertTrue(properties.getProperty("userKey1").equals("userVal1")); } + @Test + public void testGetRestartJobParametersWithDefaults() { + JsrJobOperator jobOperator = (JsrJobOperator) jsrJobOperator; + + JobExecution jobExecution = new JobExecution(1L, + new JobParametersBuilder().addString("prevKey1", "prevVal1").addString("prevKey2", "prevVal2").toJobParameters()); + + Properties defaultProperties = new Properties(); + defaultProperties.setProperty("prevKey2", "not value 2"); + Properties userProperties = new Properties(defaultProperties); + + Properties properties = jobOperator.getJobRestartProperties(userProperties, jobExecution); + + assertTrue(properties.size() == 2); + assertTrue(properties.getProperty("prevKey1").equals("prevVal1")); + assertTrue("prevKey2 = " + properties.getProperty("prevKey2"), properties.getProperty("prevKey2").equals("not value 2")); + } + @Test public void testNewJobParametersOverridePreviousRestartParameters() { JsrJobOperator jobOperator = (JsrJobOperator) jsrJobOperator;