) . However, in ...">

Why do I need the prefix "batch:" in my spring beans

I see everywhere in Spring Batch examples where the tags are (i.e. <job></job>) . However, in my xml files I need to include a "package". For example <batch:job></batch:job>

Why? Is this a version? I would like to skip tags by dropping the package: in all cases, if possible.

+4
source share
2 answers

batch is an alias in your XML file for the http://www.springframework.org/schema/batch namespace. You will have something similar at the beginning of your XML:

 xmlns:batch="http://www.springframework.org/schema/batch" 

This means that whenever you prefix an element with batch: you indicate that this element is the one that defines Spring. This is necessary to eliminate possible ambiguities (there may be other structures around the definition of the <job> element).

You can define a default namespace for all elements in the XML document, so if the namespace does not have prefixes, it will be the one the ad refers to. This default namespace is defined by the xmlns="..." attribute and is usually assigned to the http://www.springframework.org/schema/beans namespace (where the <beans> element and many other basic types are located).

You can:

1) Change batch to something shorter, like b if you want to clear

 <beans ... xmlns:b="http://www.springframework.org/schema/batch"> ... <b:job></b:job> ... </beans> 

2) Make the batch default namespace (with xmlns="http://www.springframework.org/schema/batch" ) and use the beans namespace and others, if necessary. You can even declare all your package elements in a separate XML file with this default namespace, and <beans:import> in the 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> 
+8
source

You can add xmlns = "http://www.springframework.org/schema/batch" to the root element and avoid the prefix, for example:

 <flow id="flowId" xmlns="http://www.springframework.org/schema/batch"><step id=""/><step id=""/></flow> 
0
source

Source: https://habr.com/ru/post/1490514/


All Articles