spring-native icon indicating copy to clipboard operation
spring-native copied to clipboard

Update batch-io sample with FlatFileItemReader

Open fmbenhassine opened this issue 2 years ago • 2 comments

This commit updates the batch-io sample to make the item reader reads data from a flat file (disk IO), as the sample name implies.

However, with this change, the sample fails with the same issue reported in #459 . Any idea why the sample works when the reader extends AbstractItemCountingItemStreamItemReader but not when it extends FlatFileItemReader?

fmbenhassine avatar May 20 '22 18:05 fmbenhassine

Indeed I see the error:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'job': Unsatisfied dependency expressed through method 'job' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'step1': Unsatisfied dependency expressed through method 'step1' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'reader': Invocation of init method failed; nested exception is org.springframework.beans.factory.support.ScopeNotActiveException: Error creating bean with name 'scopedTarget.reader': Scope 'step' is not active for the current thread; consider defining a scoped proxy for this bean if you intend to refer to it from a singleton; nested exception is java.lang.IllegalStateException: No context holder available for step scope
	at org.springframework.aot.beans.factory.InjectedConstructionResolver.resolve(InjectedConstructionResolver.java:88) ~[na:na]
	at org.springframework.aot.beans.factory.InjectedElementResolver.resolve(InjectedElementResolver.java:35) ~[batch-io:0.12.1-SNAPSHOT]
	at org.springframework.aot.beans.factory.InjectedElementResolver.create(InjectedElementResolver.java:66) ~[batch-io:0.12.1-SNAPSHOT]
	at org.springframework.aot.beans.factory.BeanDefinitionRegistrar$BeanInstanceContext.create(BeanDefinitionRegistrar.java:211) ~[na:na]
...
Caused by: java.lang.IllegalStateException: No context holder available for step scope
	at org.springframework.batch.core.scope.StepScope.getContext(StepScope.java:167) ~[batch-io:4.3.6]
	at org.springframework.batch.core.scope.StepScope.get(StepScope.java:99) ~[batch-io:4.3.6]
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:371) ~[batch-io:5.3.21]
	... 61 common frames omitted

Since we focus mostly on Spring Boot 3 these days, I think I am going to just apply it on the https://github.com/spring-projects-experimental/spring-native/tree/sb-3.0.x branch unless @aclement see something obvious we can fix.

sdeleuze avatar Jul 12 '22 10:07 sdeleuze

Hum, your PR seems to break the AOT mode on the JVM as well (tested with ./build.sh -a on both main and sb-3.0.x branches). Pinging @snicoll in case this could be something we don't support yet.

sdeleuze avatar Jul 12 '22 11:07 sdeleuze

Superseded by the AOT smoke tests.

snicoll avatar Nov 17 '22 15:11 snicoll