diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/CoreNamespaceUtils.java b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/CoreNamespaceUtils.java
index c70ecce0c..2d0d5fe61 100644
--- a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/CoreNamespaceUtils.java
+++ b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/CoreNamespaceUtils.java
@@ -161,4 +161,25 @@ public class CoreNamespaceUtils {
return StringUtils.hasText(abstractAttr) && Boolean.valueOf(abstractAttr);
}
+ /**
+ * Check that the schema location declared in the source file being parsed
+ * matches the Spring Batch version. (The old 2.0 schema is not 100%
+ * compatible with the new parser, so it is an error to explicitly define
+ * 2.0. It might be an error to declare spring-batch.xsd as an alias, but
+ * you are only going to find that out when one of the sub parses breaks.)
+ *
+ * @param element the element that is to be parsed next
+ * @return true if we find a schema declaration that matches
+ */
+ public static boolean namespaceMatchesVersion(Element element) {
+ return matchesVersionInternal(element) && matchesVersionInternal(element.getOwnerDocument().getDocumentElement());
+ }
+
+ private static boolean matchesVersionInternal(Element element) {
+ String schemaLocation = element.getAttributeNS("http://www.w3.org/2001/XMLSchema-instance", "schemaLocation");
+ return schemaLocation.matches("(?m).*spring-batch-2.1.xsd.*")
+ || schemaLocation.matches("(?m).*spring-batch.xsd.*")
+ || !schemaLocation.matches("(?m).*spring-batch.*");
+ }
+
}
diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/JobParser.java b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/JobParser.java
index aac11cf2a..96dcba420 100644
--- a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/JobParser.java
+++ b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/JobParser.java
@@ -58,8 +58,7 @@ public class JobParser extends AbstractSingleBeanDefinitionParser {
@Override
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
- if (!namespaceMatchesVersion(element)
- || !namespaceMatchesVersion(element.getOwnerDocument().getDocumentElement())) {
+ if (!CoreNamespaceUtils.namespaceMatchesVersion(element)) {
parserContext.getReaderContext().error(
"You cannot use spring-batch-2.0.xsd with Spring Batch 2.1. Please upgrade your schema declarations "
+ "(or use the spring-batch.xsd alias if you are feeling lucky).", element);
@@ -142,21 +141,4 @@ public class JobParser extends AbstractSingleBeanDefinitionParser {
}
- /**
- * Check that the schema location declared in the source file being parsed
- * matches the Spring Batch version. (The old 2.0 schema is not 100%
- * compatible with the new parser, so it is an error to explicitly define
- * 2.0. It might be an error to declare spring-batch.xsd as an alias, but
- * you are only going to find that out when one of the sub parses breaks.)
- *
- * @param element the element that is to be parsed next
- * @return true if we find a schema declaration that matches
- */
- private boolean namespaceMatchesVersion(Element element) {
- String schemaLocation = element.getAttributeNS("http://www.w3.org/2001/XMLSchema-instance", "schemaLocation");
- return schemaLocation.matches("(?m).*spring-batch-2.1.xsd.*")
- || schemaLocation.matches("(?m).*spring-batch.xsd.*")
- || !schemaLocation.matches("(?m).*spring-batch.*");
- }
-
}
diff --git a/spring-batch-core/src/main/resources/META-INF/spring.schemas b/spring-batch-core/src/main/resources/META-INF/spring.schemas
index 17fec72a7..df18c6979 100644
--- a/spring-batch-core/src/main/resources/META-INF/spring.schemas
+++ b/spring-batch-core/src/main/resources/META-INF/spring.schemas
@@ -1,3 +1,3 @@
http\://www.springframework.org/schema/batch/spring-batch.xsd=/org/springframework/batch/core/configuration/xml/spring-batch-2.1.xsd
http\://www.springframework.org/schema/batch/spring-batch-2.1.xsd=/org/springframework/batch/core/configuration/xml/spring-batch-2.1.xsd
-http\://www.springframework.org/schema/batch/spring-batch-2.0.xsd=/org/springframework/batch/core/configuration/xml/spring-batch-2.0-error.xsd
\ No newline at end of file
+http\://www.springframework.org/schema/batch/spring-batch-2.0.xsd=/org/springframework/batch/core/configuration/xml/spring-batch-2.0.xsd
\ No newline at end of file
diff --git a/spring-batch-core/src/main/resources/org/springframework/batch/core/configuration/xml/spring-batch-2.0-error.xsd b/spring-batch-core/src/main/resources/org/springframework/batch/core/configuration/xml/spring-batch-2.0-error.xsd
deleted file mode 100644
index 2ec0ea03b..000000000
--- a/spring-batch-core/src/main/resources/org/springframework/batch/core/configuration/xml/spring-batch-2.0-error.xsd
+++ /dev/null
@@ -1,16 +0,0 @@
-
-
-
-
-
-
diff --git a/spring-batch-core/src/main/resources/org/springframework/batch/core/configuration/xml/spring-batch-2.0.xsd b/spring-batch-core/src/main/resources/org/springframework/batch/core/configuration/xml/spring-batch-2.0.xsd
new file mode 100644
index 000000000..9f8241f3d
--- /dev/null
+++ b/spring-batch-core/src/main/resources/org/springframework/batch/core/configuration/xml/spring-batch-2.0.xsd
@@ -0,0 +1,833 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Defines a job composed of a set of steps and
+ transitions between steps. The job will be exposed in
+ the enclosing bean factory as a component of type Job
+ that can be launched using a JobLauncher.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Defines a stage in job processing backed by a
+ Step. The id attribute must be specified since this
+ step definition will be referred to from other elements
+ to form a Job flow.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ A reference to a JobExecutionListener (or a POJO
+ if using before-job-method / after-job-method or
+ source level annotations).
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ A bean definition for a step listener (or POJO if using *-method attributes or source level
+ annotations)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Defines a stage in job processing backed by a
+ Step. The id attribute must be specified. The
+ step requires either a chunk definition,
+ a tasklet reference, or a reference to a
+ (possibly abstract) parent step.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Declares job should split here into two or more subflows.
+
+
+
+
+
+
+
+ A subflow within a job, having the same format as a job, but without a separate identity.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Declares job should query a decider to determine where execution should go next.
+
+
+
+
+
+
+
+
+ The decider is a reference to a JobExecutionDecider that can produce a status to base
+ the next
+ transition on.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ The tasklet is a reference to another bean definition that implements the Tasklet interface.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ A reference to a listener, a POJO with a
+ listener-annotated method, or a POJO with
+ a method
+ referenced by a *-method attribute.
+
+
+
+
+
+
+
+
+
+ A class name used to create a listener from the default constructor.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Defines a transition from this step to the
+ next one depending on the value of the exit
+ status.
+
+
+
+
+
+ A pattern to match against the exit status
+ code. Use * and ? as wildcard characters. When a
+ step finishes the most
+ specific match will be chosen to select the next step. Hint:
+ always include a default
+ transition with on="*".
+
+
+
+
+ The name of the step to go to next. Must resolve to one of the other steps in this job.
+
+
+
+
+
+
+
+
+ Declares job should be stop at this point and provides pointer where execution should continue when
+ the job is restarted.
+
+
+
+
+
+ A pattern to match against the exit status code. Use * and ? as wildcard characters.
+ When a step finishes the most specific match will be chosen to select the next step.
+
+
+
+ The name of the step to start on when the stopped job is restarted.
+ Must resolve to one of the other steps in this job.
+
+
+
+
+
+
+
+ Declares job should end at this point, without the possibility of restart.
+ BatchStatus will be COMPLETED. ExitStatus is configurable.
+
+
+
+
+
+ A pattern to match against the exit status code. Use * and ? as wildcard characters.
+ When a step finishes the most specific match will be chosen to select the next step.
+
+
+
+
+ The exit code value to end on, defaults to COMPLETED.
+
+
+
+
+
+
+
+ Declares job should fail at this point. BatchStatus will be FAILED. ExitStatus is configurable.
+
+
+
+
+
+ A pattern to match against the exit status code. Use * and ? as wildcard characters.
+ When a step finishes the most specific match will be chosen to select the next step.
+
+
+
+
+ The exit code value to end on, defaults to FAILED.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ The name of the parent bean from which the configuration should inherit.
+
+
+
+
+
+
+
+
+
+
+
+
+ Is this bean "abstract", that is, not meant to be instantiated itself
+ but rather just serving as parent for concrete child bean definitions?
+ The default is "false". Specify "true" to tell the bean factory to not
+ try to instantiate that particular bean in any case.
+
+ Note: This attribute will not be inherited by child bean definitions.
+ Hence, it needs to be specified per abstract bean definition.
+
+
+
+
+
+
+
+
+
+ Should this list be merged with the corresponding list provided
+ by the parent? If not, it will overwrite the parent list.
+
+
+
+
+
+
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/JobParserExceptionTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/JobParserExceptionTests.java
index 3c17970da..76761778f 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/JobParserExceptionTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/JobParserExceptionTests.java
@@ -61,7 +61,7 @@ public class JobParserExceptionTests {
assertTrue("Wrong message: "+message, message.matches("(?s).*You cannot use spring-batch-2.0.xsd.*"));
} catch (BeanDefinitionStoreException e) {
// Probably the internet is not available and the schema validation failed.
- // We don't want an automated build to fail if that happens.
+ fail("Wrong exception when schema didn't match: " + e.getMessage());
}
}