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<T> implements ItemStreamReader<T> {
/** Registered ItemStreamReaders. */
private List<AbstractCursorItemReader<?>> cursorItemReaders;
/** Mandatory Unifying Mapper Implementation. */
private UnifyingItemsMapper<T> 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:
<property name="unifyingMapper">
<bean class="com.common.batch.mapper.DefaultUnifyingStringItemsMapper" />
</property>
here is the implementation of the UnifyingItemsMapper
you are using:
public class DefaultUnifyingStringItemsMapper implements UnifyingItemsMapper<String> {
/** {@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<Customer>
and configure it for your CompositeCursorItemReader#unifyingMapper
Or just use your itemReader
directly if you don't need a UnifyingItemsMapper
:
<job id="compositeJdbcReaderJob" xmlns="http://www.springframework.org/schema/batch">
<step id="compositeJdbcReaderStep" next="compositeJdbcReaderStep2">
<tasklet>
<chunk reader="itemReader1" writer="itemWriter" commit-interval="5" />
</tasklet>
</step>
<step id="compositeJdbcReaderStep2">
<tasklet>
<chunk reader="itemReader2" writer="itemWriter2" commit-interval="5" />
</tasklet>
</step>
</job>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…