Announcement Announcement Module
Collapse
No announcement yet.
scope "step" does not work together with Annotation "@BeforeStep" Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • scope "step" does not work together with Annotation "@BeforeStep"

    Hi,

    I am using scope='step' and @BeforeStep Annotaion in my comosite item writer. I am getting the following error

    Encountered an error executing the step: class java.lang.IllegalArgumentException: Unable to invoke method

    I saw similar issue logged in the following post and it says it has been fixed.
    https://jira.springsource.org/browse/BATCH-1230

    I am using spring batch 2.1.6. Please help

    Thanks
    Shravan

  • #2
    According to that JIRA link there is a test which asserts that this works since 2.0.1. Are you sure you don't have an old version in your classpath? If so, then please try and provide a test case, and/or some more detailed steps to reproduce the problem.

    Comment


    • #3
      I verified this we are using spring batch 2.1.6 version.

      The scenario is we have a step for which we need to pass the parameter dynamically for which we are using scope ="step" and we want to perform some logic @Before step.
      Code looks something like this

      <beans:bean id="nyhoCheckFlatFileWriter" class="org.springframework.batch.item.file.FlatFil eItemWriter" scope="step">
      <beans roperty name="resource"
      value="#{jobParameters['feedFileName']}" />

      @BeforeStep
      public void retrieveInterstepData(StepExecution stepExecution) {

      this.jobExecution = stepExecution.getJobExecution();
      this.executionContext = jobExecution.getExecutionContext();
      }

      Please help

      Comment


      • #4
        Code:
        <bean id="nyhoCheckFlatFileWriter"	class="org.springframework.batch.item.file.FlatFileItemWriter" scope="step">
           <property name="jobExecution" value="#{stepExecution.jobExecution}"  />
         ...
        </bean>
        Should work fine (no need for @BeforeStep). I'm still curious to know why it doesn't work for you, but since you don't need it, I guess it's not a very interesting problem for anyone else.

        Comment


        • #5
          Hi Dave,

          My code is something like this..

          CompositeItem writer difination

          <beans:bean id="citiIssueCompoItemWriter"
          class="com.metlife.metcheck.batch.domain.itemwrite r.extractor.CitiBankIssueCompositeItemWriter">
          <beansroperty name="delegates">
          <beans:list>
          <beans:ref bean="detailRecordWriter" />
          <beans:ref bean="accountTrailerWriter" />
          </beans:bean>


          In the detailRecordWriter defination

          <beans:bean id="detailRecordWriter"
          class="org.springframework.batch.item.file.FlatFil eItemWriter" scope="step">
          <beansroperty name="resource"
          value="#{stepExecution.jobExecution}" />
          <beansroperty name="shouldDeleteIfExists" value="true" />
          ..........
          ......
          </beans:bean>


          In my Composite Item writer class i am using befor step method to get the reference to stepExecution

          public class CitiBankIssueCompositeItemWriter implements ItemWriter, FlatFileFooterCallback {
          private JobExecution jobExecution;

          @BeforeStep
          public void retrieveInterstepData(StepExecution stepExecution) {

          this.jobExecution = stepExecution.getJobExecution();
          this.executionContext = jobExecution.getExecutionContext();
          }

          public void setDelegates(List<ItemWriter> delegates) {

          this.delegates = delegates;
          }

          public void write(List item) throws Exception {
          }

          }

          this is what causing the above exception. Please help..i have checked we are using spring batch 2.1.6

          Comment


          • #6
            Hi Dave,

            I have also face similar issue when the the scope is step. The beforeStep() is not even called during intialization.

            Comment


            • #7
              But you don't actually need to use a step listener for this use case (as I explained above, albeit with a bad bean definition - it should have been class="com.metlife.metcheck.batch.domain.itemwrite r.extractor.CitiBankIssueCompositeItemWriter"). In your example the step listener is not even in step scope, so I haven't understood the problem yet.

              Comment

              Working...
              X