我在我的 Spring Batch 代码中遇到一个错误,它说:在类路径资源中定义名称为“itemReader”的 bean 创建错误,无法将类型“$Proxy0”的属性值转换为属性“preparedStatementSetter”所需的类型。
这是我的 ItemReader 代码:
<beans:bean id="itemReader"
class="org.springframework.batch.item.database.JdbcCursorItemReader">
<beans:property name="dataSource" ref="dataSource"/>
<beans:property name="sql" value="select * from Trans_Tst WHERE id =?"/>
<beans:property name="rowMapper" ref="romMapper"/>
<beans:property name="preparedStatementSetter" ref="ReaderSqlParameterSetter"/>
</beans:bean>
<beans:bean id="ReaderSqlParameterSetter"
class="sa.com.anb.itg.dev.settlement.batch.ReaderSqlParameterSetter" scope="step">
<beans:property name="id" value="#{jobParameters[id]}"/>
</beans:bean>
这是我的 ReaderSqlParameterSetter 类:
package sa.com.anb.itg.dev.settlement.batch;
import java.sql.PreparedStatement;
import org.springframework.batch.item.database.ItemPreparedStatementSetter;
import java.sql.SQLException;
public class ReaderSqlParameterSetter implements
ItemPreparedStatementSetter<transactionas>{
public void setValues(transactionas transactionas,PreparedStatement ps)
throws SQLException {
ps.setInt(1, transactionas.GetID());
}
}
<beans:bean id="jdbcWriter"
class="org.springframework.batch.item.database.JdbcBatchItemWriter">
<beans:property name="dataSource" ref="dataSource"/>
<beans:property name="sql" value="update Trans_Tst set ()amount) values (?)
where id= ?"/>
<beans:property name="preparedStatementSetter"
ref="WriterSqlParameterSetter"/>
</beans:bean>
<beans:bean id="WriterSqlParameterSetter"
class="sa.com.anb.itg.dev.settlement.batch.WriterSqlParameterSetter" scope="step">
<beans:property name="amount" value="#{jobParameters[amount]}"/>
<beans:property name="id" value="#{jobParameters[id]}"/>
</beans:bean>
public class WriterSqlParameterSetter implements PreparedStatementSetter {
transactionas transactionas = new transactionas();
public void setValues(PreparedStatement ps) throws SQLException {
ps.setDouble(1, transactionas.GetAmount());
ps.setInt(2, transactionas.GetID());
}
}
任何人都可以帮助我吗?