I already generated the java classes corresponding to my xml files (through jaxb tool).
Then I wrote my configuration file as following:
<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>
<!-- MULTI Reader -->
<bean id="multiResourceReader"
class=" org.springframework.batch.item.file.MultiResourceItemReader">
<property name="resources" value="classpath:xmls/*.xml" />
<property name="delegate" ref="xmlItemReader" />
</bean>
<!-- Reader -->
<bean id="xmlItemReader" class="org.springframework.batch.item.xml.StaxEventItemReader">
<property name="fragmentRootElementName" value="T_Document" />
<property name="unmarshaller" ref="invoiceUnMarshaller" />
</bean>
<!-- Unmarshaller -->
<bean id="invoiceUnMarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
<property name="contextPath" value="com.xxx.model.inputJaxB" />
</bean>
<!-- Writer -->
<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>
<!-- Marshaller -->
<bean id="invoiceMarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
<property name="classesToBeBound">
<list>
<value>com.xxx.model.output.Facture</value>
</list>
</property>
</bean>
and here is my App.java:
public class App {
public static long customerID = 201832;
public static void main(String[] args) {
String[] springConfig = { "spring/batch/config/context.xml", "spring/batch/jobs/job-bgh.xml" };
@SuppressWarnings("resource")
ApplicationContext context = new ClassPathXmlApplicationContext(springConfig);
JobLauncher jobLauncher = (JobLauncher) context.getBean("jobLauncher");
Job job = (Job) context.getBean("bghJob");
try {
JobExecution execution = jobLauncher.run(job, new JobParameters());
System.out.println("Exit Status : " + execution.getStatus());
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("Done");
}
}
My problem is that the xml output file created is almost empty. Here it is:
<?xml version="1.0" encoding="UTF-8"?>
<Facture></Facture>
What am I missing please ??? Why is my output xml empty?
No comments:
Post a Comment