Spring Batch configuration error in processor

I want to set up a Spring Batch job but I am getting the following error, how can I solve it?

Mistake: enter image description here

Reader:

import org.springframework.batch.item.ItemReader;

public class MoviesReader implements ItemReader<SearchResponseRO>, StepExecutionListener {

    @Override
    public SearchResponseRO read() throws Exception {
        return new SearchResponseRO();
    }
}

      

CPU:

import org.springframework.batch.item.ItemProcessor;

public class MoviesProcessor implements ItemProcessor<SearchResponseRO, Movie> {
    @Override
    public Movie process(SearchResponseRO searchResponseRO) throws Exception {
        return new Movie();
    }
}

      

What do I need to change to fix the problem?

Thank you.

+7


source to share


1 answer


You need to specify the type for the operation chunk

. In your case, it will be <SearchResponseRO, Movie>

.

return stepBuilderFactory.get("downloadStep").<SearchResponseRO, Movie>chunk(10)
  .reader(reader)
  .processor(processor)
  .....

      

Without a type, it defaults to <Object, Object>

:



stepBuilderFactory.get("test").chunk(10)
        .reader(new ItemReader<Object>() {
            @Override
            public Object read() throws Exception, UnexpectedInputException, ParseException, NonTransientResourceException {
                return null;
            }
        })
        .processor(new ItemProcessor<Object, Object>() {
            @Override
            public Object process(Object o) throws Exception {
                return null;
            }
        })
        .writer(new ItemWriter<Object>() {
            @Override
            public void write(List<?> list) throws Exception {

            }
        })
        .build();

      

If you look at the definition of a method chunk

, it accepts int

but returns SimpleStepBuilder<I, O>

. Since there is no way to provide types for I

and O

, you must essentially cast them to the values ​​you want. I believe the syntax .<Type>

is just a convenience for direct casting when chaining calls, so the following two things should be the same:

public void castGenericReturnType() {
    System.out.println(this.<Integer>genericReturn(1));
    System.out.println((Integer) genericReturn(1));
}

public <I> I genericReturn(Object objectToCast) {
    return (I) objectToCast;
}

      

+12


source







All Articles