我正在尝试访问RowMapper中的RowMapper,但无法访问。我在xml中有一个名为‘pro1’的属性集。我希望设置它,但它不是设置,我还在RowMapper中添加了一个@BeforeStep方法,希望我能得到stepExecutionContext,但是这个方法从未被调用过。还有什么需要我做的吗?
以下是我的xml:
<bean id="bean1"
class="org.springframework.batch.item.database.JdbcCursorItemReader"
scope="step">
<property name="dataSource" ref="dataSource" />
<property name="sql"
value="${sql}"/>
<property name="fetchSize" value="${fetchSize}"></property>
<property name="rowMapper">
<bean id="rowMapper1" class="c.p.MyRowMapper" scope="step">
<property name="prop1" value="${prop1}"></property>
</property>
这是我的RowMapper:
public class MyRowMapper implements RowMapper<Object>{
private String prop1;
private StepExecution se;
public String getProp1() {
return stepFatpCount;
}
public void setProp1(String rop1) {
this. prop1 = prop1;
}
@BeforeStep
public void beforeStep(StepExecution stepExecution){
this.se = stepExecution;
}
}在这个步骤之前的另一步中,我在stepExecutionContext中设置了一些属性,我想在RowMapper中使用它们。同样的事情在ItemProcessor中起作用,但在RowMapper中不起作用。请让我知道,如果我需要做更多的懒散绑定或任何其他问题。谢谢。
发布于 2016-02-25 22:10:42
步骤执行上下文在步骤之间不共享。也许你是说任务执行的上下文?
我认为您可以将rowMapper1注册为步骤中的侦听器(使用<listeners>标记),但是如果您只想从作业执行上下文中读取一些值,则可以使用
value="#{jobExecutionContext['foobar']}"如果您确实希望从步骤执行上下文中注入一些值,则只需替换上面的stepExecutionContext即可。
https://stackoverflow.com/questions/35639006
复制相似问题