I have an issue with custom my Header and Trailer for BeanIO, consider this beanio xml below
<stream name="stream" format="fixedlength" >
<record name="header" minOccurs="1" maxOccurs="1" class="myHeaderBean">
<field name="recordType" length="1" position="0" rid="true" literal="H" />
<field name="generatedDate" length="8" position="1" />
</record>
<record name="details" minOccurs="1" maxOccurs="unbounded" class="myBean">
<field name="recordType" length="1" position="0" rid="true" literal="D" />
<!-- other fields follows -->
</record>
<record name="trailer" minOccurs="1" maxOccurs="1" class="myTrailerBean">
<field name="recordType" length="1" position="0" rid="true" literal="T" />
<field name="recordTotal" length="12" position="1" />
</record>
</stream>
and this is my spring-batch job xml config
<batch:job id="myJob" incrementer="incrementer">
<batch:step id="stepProcess">
<batch:tasklet transaction-manager="transactionManager">
<batch:chunk reader="myReader" processor="myProcessor"
writer="myWriter" commit-interval="100" skip-limit="1000"
retry-limit="10">
<batch:skippable-exception-classes>
<batch:include class="org.beanio.InvalidRecordException" />
<batch:exclude class="java.io.FileNotFoundException" />
</batch:skippable-exception-classes>
<batch:retryable-exception-classes>
<batch:include
class="org.springframework.dao.DeadlockLoserDataAccessException" />
</batch:retryable-exception-classes>
</batch:chunk>
</batch:tasklet>
</batch:step>
</batch:job>
<bean id="myReader" class="org.beanio.spring.BeanIOFlatFileItemReader">
<property name="streamMapping" value="${mapping.file.location}" />
<property name="resource" value="${input.file.location}" />
</bean>
<bean id="incrementer"
class="org.springframework.batch.core.launch.support.RunIdIncrementer" />
<bean id="myProcessor"
class="myProcessor" />
<bean id="myWriter"
class="myWriter" />
Java codes goes like this
@Component
public class myProcessor
implements ItemProcessor<myBean, myEntity> {
@Override
public myEntity process(myBean myBean)
throws Exception {
// code to build myEntity here..
return myEntity;
}
}
@Component
public class myWriter
implements ItemWriter<myEntity> {
@Override
public void write(List<? extends myEntity> myEntities) throws Exception {
// code to save myEntities here
}
}
Issue -> ClassCastException on process because myHeaderBean can't be translated to myBean -- which is the only bean passed during processs
Question -> How to avoid passing myHeaderBean and myTrailerBean during process? Sorry can't find a good article on internet for this issue.
Thanks in advance