I am developing Spring Batch CompositeItemReader & Writer Example. I developed XML file and able to compile code successfully, but when running mu sample co
Spring is trying to get the property cutomerNumber from the String class :
Invalid property 'customerNumber' of bean class [java.lang.String]
which is wrong because the String is not supposed to be configured as the item of your job 's step, the Item in this context is supposed to be the Customer.
your beans are configured correctly except for one bean :compositeItemReader
The read method of this bean is returning a String instead of a Customer which is because of this :
public class CompositeCursorItemReader implements ItemStreamReader {
/** Registered ItemStreamReaders. */
private List> cursorItemReaders;
/** Mandatory Unifying Mapper Implementation. */
private UnifyingItemsMapper unifyingMapper;
@Override
public T read() throws Exception, UnexpectedInputException, ParseException, NonTransientResourceException {
// read from all registered readers
List items = new ArrayList();
for (AbstractCursorItemReader> cursorItemReader : cursorItemReaders) {
items.add(cursorItemReader.read());
}
// delegate to mapper
return unifyingMapper.mapItems(items);
}
}
Its property UnifyingMapper is configured as follow:
here is the implementation of the UnifyingItemsMapper you are using:
public class DefaultUnifyingStringItemsMapper implements UnifyingItemsMapper {
/** {@inheritDoc} */
@Override
public String mapItems(List> items) throws Exception {
if (items != null && items.size() > 0) {
StringBuilder sb = new StringBuilder();
for (Object item : items) {
if (item != null) {
sb.append(item);
}
}
if (sb.length() > 0) {
return sb.toString();
} else {
return null;
}
} else {
return null;
}
}
}
the solution to this is to create a new Class that implements UnifyingItemsMapper and configure it for your CompositeCursorItemReader#unifyingMapper
Or just use your itemReader directly if you don't need a UnifyingItemsMapper: