Spring试图
cutomerNumber从
String类中获取属性:
Invalid property 'customerNumber' of bean class [java.lang.String]
这是错误的,因为
String不应将组态为
item您的工作步骤,
Item在此情况下应将设定为
Customer。
您的bean的配置正确,除了一个bean:
compositeItemReader
由于以下原因,此bean的read方法返回a
String而不是a
Customer:
public class CompositeCursorItemReader<T> implements ItemStreamReader<T> {private List<AbstractCursorItemReader<?>> cursorItemReaders;private UnifyingItemsMapper<T> unifyingMapper;@Overridepublic 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);}}其属性UnifyingMapper配置如下:
<property name="unifyingMapper"> <bean /> </property>
这是
UnifyingItemsMapper您正在使用的实现:
public class DefaultUnifyingStringItemsMapper implements UnifyingItemsMapper<String> { @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; } }}解决方案是创建一个新类,
UnifyingItemsMapper<Customer>为您实现并配置它
CompositeCursorItemReader#unifyingMapper
或者,
itemReader如果您不需要
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>



