Skip to content

Can't Use Type ItemListenerSupport w/ StepBuilderFactory .listener Method [BATCH-2461] #1141

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
spring-projects-issues opened this issue Dec 18, 2015 · 4 comments

Comments

@spring-projects-issues
Copy link
Collaborator

Jeff opened BATCH-2461 and commented

The .listener method of StepBuilderFactory doesn't support taking arguments of type ItemListenerSupport


Affects: 3.0.6

@spring-projects-issues
Copy link
Collaborator Author

Michael Minella commented

There isn't a method on StepBuilderFactory for adding listeners. Can you paste your exact configuration so we can see what actual builder you're using?

@spring-projects-issues
Copy link
Collaborator Author

Alexis NICOLAS commented

I have the same problem, it is on SimpleStepBuilder (org.springframework.batch.core.step.builder.SimpleStepBuilder). Here in this code you can see that I have to cast FooBarItemListener as a ItemReadListener to be able to call the method, it works but it isn't then obvious to someone reading this that FooBarItemListener will also work as a ItemProcessListener and an ItemWriteListener.

    @Configuration
	@EnableBatchProcessing
	public class JobConfiguration {
	
		[...]
	
		@Autowired
		private StepBuilderFactory stepBuilderFactory;

		@Bean
		public Step stepFoo() {
			return stepBuilderFactory.get("stepFoo")
					.<Foo, Bar>chunk(100)
					.reader(fooReader())
					.processor(fooProcessor())
					.writer(barReader())
					.listener((ItemReadListener<Foo>) new FooBarItemListener()) //The problematic part
					.listener(new FooBarStepExecutionListener())
					.listener(new FooBarJobExecutionListener())
					.build();
		}
		
		[...]
		
	}
	
	public class FooBarItemListener extends ItemListenerSupport<Foo, Bar> {
	
		private static final Logger LOGGER = LoggerFactory.getLogger(FooBarItemListener.class);
		
		@Override
		public void onReadError(Exception ex) {
			LOGGER.error("Exception while reading foo: " + ex.getMessage(), ex);
		}

		@Override
		public void onProcessError(Foo item, Exception ex) {
			LOGGER.error("Exception while processsing foo " + item + " error: " + ex.getMessage(), ex);
		}

		@Override
		public void onWriteError(Exception ex, List<? extends Bar> items) {
			LOGGER.error("Exception while writing bars : " + items + " error: " + ex.getMessage(), ex);
		}
	
	}

@randeepbydesign
Copy link

Any updates on this? What is the proper usage of this class to not cause this error?

@fmbenhassine
Copy link
Contributor

Closing this as StepBuilderFactory was deprecated in v5.0 (#4188) and removed in v5.2.

@fmbenhassine fmbenhassine closed this as not planned Won't fix, can't repro, duplicate, stale Mar 19, 2025
@fmbenhassine fmbenhassine removed the status: waiting-for-triage Issues that we did not analyse yet label Mar 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants