Announcement Announcement Module
Collapse
No announcement yet.
Spring Batch 2.0 Config issue Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring Batch 2.0 Config issue

    Hi all,

    I have been using Spring Batch 1.x in my system and now considering in upgrading to 2.0

    In the past, as for readability, I considered of using anonymous bean and put the tasklet/reader/writer inline with the step:
    Code:
    <bean id="..." parent="simpleJob">
      <property name="steps">
        <list>
          <bean id = "step1" parent = "taskletStep">
            <property name = "tasklet">
              <bean class="foo.myTasklet">
                <property name="prop1" value="val1"/>
              </bean>
            </property>
          </bean>
    
          <bean id = "step2" parent = "chunkStep">
            <property name="itemReader">
              <bean class="foo.MyReader"/>
            </property>
            <property name="itemWriter">
              <bean class="foo.MyWriter">
                 <property name="someService" ref="barService"/>
              </bean>
            </property>
          </bean>
        </list>
      </property>
    <bean>
    By inlining the reader/writer/tasklet in configuration, I can easily know what each step is doing when inspecting the config.

    Config for Spring Batch 2.0 changed a lot. When I inspect the schema, I found that seems I can only provide reference to reader/writer/tasklet/listener. That mean I need to do something like
    Code:
    <job id="myJob">
      <step id="step1">
        <tasklet ref="myJob.step1.tasklet"/>
      </step>
      <step id="step2">
        <tasklet>
          <chunk reader="myJob.step2.reader" writer = "myJob.step2.writer">
             ...
          </chunk>
        </tasklet>
      </step>
    </job>
    <bean id = "myJob.step1.tasklet" class = "foo.MyTasklet">
      ....
    </bean>
    <bean id = "myJob.step2.reader" class = "foo.MyReader">
      ...
    </bean>
      ....
    That mean when I am inspecting the job, I need to go to and fro to look at what which the step is referring, and then what really is the bean. Is there any better way so I can do a more 'inline' style of config? Something like

    Code:
    <step id="step1">
      <tasklet>
        <bean class="foo.MyTasklet"/>
      </tasklet>
    </step>
    
    <step id="step2">
      <tasklet>
        <chunk  .... >
          <reader>
            <bean class="foo.MyReader/>
          </reader>
          <writer>
             <bean class="foo.MyWriter"/>
          </writer>
        </chunk>
      </tasklet>
    </step>

  • #2
    Inner beans (in the beans: namespace, not the batch: namespace as in your example) are allowed in 2.1 for listeners. If you like that feature, raise a JIRA for readers, processors and writers inside a <chunk/> too.

    Comment

    Working...
    X