Results 1 to 4 of 4

Thread: Component scanned beans & step scope.

  1. #1
    Join Date
    May 2008
    Location
    UK
    Posts
    24

    Default 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 at 02:16 PM.

  2. #2
    Join Date
    May 2008
    Location
    UK
    Posts
    24

  3. #3
    Join Date
    May 2008
    Location
    UK
    Posts
    24

    Default

    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.

    :-)

  4. #4
    Join Date
    Jun 2005
    Posts
    4,230

    Default

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •