I using spring batch for reading data from db and writing to XML file i am choosed the "StaxEventItemWriter" writes. it generating the xml file fine but with extra end document tag at the end. You can find the bug Here, due to this my batch process was failed to read the same XML file. I surf the internet and i found the one of the solution and implemented the below. Now my XML files are generated without the extra end document tag. Now all my batches are working fine.
Solution:import javax.xml.stream.XMLEventWriter; import javax.xml.stream.XMLOutputFactory; import javax.xml.stream.XMLStreamException; import org.springframework.batch.item.xml.StaxEventItemWriter; /** * @author sunilkumar.gutti * */ @SuppressWarnings("rawtypes") public class ShipmentStaxEventItemWriter extends StaxEventItemWriter { @Override protected void endDocument(XMLEventWriter writer) throws XMLStreamException { XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); if (outputFactory.isPropertySupported("com.ctc.wstx.autoCloseElements")) { outputFactory.setProperty("com.ctc.wstx.autoCloseElements", false); } } }
No comments:
Post a Comment