I used JAXB xjc tool to generate java classes from my multiple xsd files (I used an online tool to generate xsd files from my xml files).
My problem is that I don't know how to configure my context.xml to make it read all the classes (and xmls) given AND generate only one final big xml file.
Here is my context.xml:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:batch="http://www.springframework.org/schema/batch" xmlns:task="http://www.springframework.org/schema/task"
xmlns:util="http://www.springframework.org/schema/util" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/batch
http://www.springframework.org/schema/batch/spring-batch-2.2.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-3.2.xsd">
<import resource="../config/context.xml" />
<batch:job id="bghJob" parent="simpleJob">
<batch:step id="step1">
<batch:tasklet>
<batch:chunk reader="multiResourceReader" writer="xmlItemWriter"
commit-interval="1" />
</batch:tasklet>
</batch:step>
</batch:job>
<bean id="multiResourceReader"
class=" org.springframework.batch.item.file.MultiResourceItemReader">
<property name="resources" value="classpath:xml/*.xml" />
<property name="delegate" ref="xmlItemReader" />
</bean>
<bean id="xmlItemReader" class="org.springframework.batch.item.xml.StaxEventItemReader">
<property name="unmarshaller" ref="invoiceUnMarshaller" />
<property name="fragmentRootElementName" value="DocumentType" />
</bean>
<bean id="invoiceUnMarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
<property name="classesToBeBound">
<value>com.xxx.generatedByJaxb.inv.DocumentType</value>
</property>
</bean>
<bean id="xmlItemWriter" class="org.springframework.batch.item.xml.StaxEventItemWriter">
<property name="resource" value="file:xml/outputs/Facture.xml" />
<property name="marshaller" ref="invoiceMarshaller" />
<property name="rootTagName" value="Facture" />
</bean>
<bean id="invoiceMarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
<property name="classesToBeBound">
<value>com.xxx.generatedByJaxb.inv.DocumentType</value>
</property>
</bean>
It seems like I can only read one class (for example com.xxx.generatedByJaxb.inv.DocumentType) and I have to specify the root tag but no one of my generated java classes has the annotation XmlRootElement
How can I configure my job to achieve my goal please?
Thank you.
Just use the contextPath
property:
<property name="contextPath"
value="com.xxx.generatedByJaxb.inv:com.yyy.generatedByJaxb.inv"/>
This is a list of relevant packages, :
-separated.
Check also other properties, they might be handy.