Spring 注入实现 bean

Spring injecting implementation bean

我有来自 conf spring 文件的以下片段:

<bean id="taskletStep" abstract="true" class="org.springframework.batch.core.step.tasklet.TaskletStep">
        <property name="jobRepository" ref="jobRepository"/>
        <property name="transactionManager" ref="transactionManager"/>
    </bean>

    <bean id="hello" class="com.techavalanche.batch.PrintTasklet">
        <property name="message" value="Hello"/>
    </bean>

    <bean id="world" class="com.techavalanche.batch.PrintTasklet">
        <property name="message" value=" World!"/>
    </bean>

    <bean id="mySimpleJob" class="org.springframework.batch.core.job.SimpleJob">
        <property name="name" value="mySimpleJob" />
        <property name="steps">
            <list>
                <bean parent="taskletStep">
                    <property name="tasklet" ref="hello"/>
                </bean>

                <bean parent="taskletStep">
                    <property name="tasklet" ref="world"/>
                </bean>
            </list>
        </property>

我不是很清楚以下几点:

<bean parent="taskletStep">
                    <property name="tasklet" ref="hello"/>
                </bean>

taskletStep 是一个接口,没有任何 属性。但是代码工作正常,似乎注入了 ID 为 "hello" 的 bean。因此我要问,这是从配置文件将 bean 实现(id:hello)注入接口 bean(id:taskletStep[=21)的标准方法吗=])?

这是 Spring 批处理作业中的一个 tasklet 步骤。你在做什么完全没问题。或者,您也可以这样做:

<job id="mySimpleJob">
    <step id="step1">
        <tasklet ref="hello"/>
    </step>

    <step id="step2">
        <tasklet ref="world"/>
    </step>
</job>

这里是一个完整的参考: http://docs.spring.io/spring-batch/reference/htmlsingle/