xml文件中配置itemSqlParameterSourceProvider是可以的:
<bean id="billDbWriter"
class="com.aa.bb.AABatchWriter">
<property name="dataSource" ref="dataSource" />
<property name="sql"
value="insert into bills(id,user_id,fees,paid_fees,unpaid_fees,pay_status) values(:id,:user.id,:fees,:paidFees,:unpaidFees,:payStatus)" />
<property name="itemSqlParameterSourceProvider"
ref="itemSqlParameterSourceProvider" />
<bean id="itemSqlParameterSourceProvider"
class="org.springframework.batch.item.database.BeanPropertyItemSqlParameterSourceProvider" />
但是假如放到java代码中,用@Resource和@AutoWired都引用不到itemSqlParameterSourceProvider,会报错:
public class AABatchWriter<T> implements ItemWriter<T> { @Resource
BeanPropertyItemSqlParameterSourceProvider itemSqlParameterSourceProvider; /* (non-Javadoc)
* @see org.springframework.batch.item.ItemWriter#write(java.util.List)
*/
public void write(List<? extends T> items) throws Exception {
// TODO Auto-generated method stub } }