Announcement Announcement Module
Collapse
No announcement yet.
Component scanned beans & step scope. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Component scanned beans & step scope.

    Forgive the question if its an old chestnut. :-)

    Is it possible to combine step scope to pass job parameters into beans within in a job which are created on context initialisation via @Component annotations.

    This is within a webapp I'm working on. If I define the beans using xml they don't autowire dependencies hence we're using @Component throughout our project.

    I am pondering something like

    <bean id="myBean" ref="componentBean"
    scope="step" />

    In order to "late bind" parameters at
    run time.

    TIA,

    David.
    Last edited by dvb123; Jul 11th, 2011, 02:16 PM.

  • #2
    http://static.springsource.org/sprin...StepScope.html

    RTFM! :-)

    looks like a no.

    Comment


    • #3
      Finally engaged brain & figured this out.

      Code:
       <bean id="fetchTasklet"
              class="com.acme.batch.FetchTasklet"
              scope="step">
          <property name="myService" ref="myServiceImpl"/>
          <property name="prop1"  value="#{jobParameters['prop1']}" />
        </bean>
      So the bean dependencies are resolved by classic Spring DI, and are annotated @Component. Step scope lets the runtime parameter be passed to the Tasklet.
      This is now working.

      :-)

      Comment


      • #4
        This should work (but I haven't tested it):

        Code:
        @Component
        @Scope("step")
        public class FetchTasklet implements Tasklet {
            @Value("#{jobParameters['prop1']")
            private String prop1;
            ...
        }
        There's also no reason (as you discovered) why XML beans should not take part in autowiring.

        Comment

        Working...
        X