I see everywhere in Spring Batch examples where the tags are (i.e. <job></job>)
. However in my xml files I have to include 'batch'. For example <batch:job></batch:job>
Why is that? Is that a version thing? I'd like to thin out the tags by dropping batch: in all of them if that's possible.
batch
is the alias in your XML file for the http://www.springframework.org/schema/batch
namespace. You'll have something like this at the beggining of your XML:
xmlns:batch="http://www.springframework.org/schema/batch"
This means that whenever you're prefixing an element with batch:
, you're specifying that the element is the one Spring defines. This is necessary to clear out possible ambiguities (there might be other frameworks around defining the <job>
element).
It is possible to define a default namespace for all elements in the XML document, so that if no namespace is prefixed, it'll be the one that the declaration is referring to. This default namespace is defined with the xmlns="..."
attribute, and is usually assigned to the http://www.springframework.org/schema/beans
namespace (where the <beans>
element and many more of the basic types reside).
You could either:
1) Change batch
to something shorter such as b
if you want to clean up
<beans ... xmlns:b="http://www.springframework.org/schema/batch">
...
<b:job></b:job>
...
</beans>
2) Make batch
the default namespace (with xmlns="http://www.springframework.org/schema/batch"
) and use the beans
namespace and others when needed. You could even declare all your batch elements in a separate xml file with this namespace as default, and <beans:import>
it in your main applicationContext.xml
.
<beans:beans xmlns="http://www.springframework.org/schema/batch"
xmlns:beans="http://www.springframework.org/schema/beans">
<job>...</job>
<job>...</job>
</beans:beans>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With