簡體   English   中英

彈簧注入實現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: taskletStep )注入bean實現(id: hello )的標准方法嗎?

這是Spring Batch Job中的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/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM