Results 1 to 7 of 7

Thread: scope "step" does not work together with Annotation "@BeforeStep"

  1. #1

    Default 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. #2
    Join Date
    Jun 2005
    Posts
    4,232

    Default

    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.

  3. #3

    Default

    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

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

    Default

    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.

  5. #5

    Default

    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

  6. #6
    Join Date
    Mar 2011
    Posts
    14

    Default

    Hi Dave,

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

  7. #7
    Join Date
    Jun 2005
    Posts
    4,232

    Default

    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.

Posting Permissions

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