spring-attic / spring-native

Spring Native is now superseded by Spring Boot 3 official native support
https://docs.spring.io/spring-boot/docs/current/reference/html/native-image.html
Apache License 2.0
2.74k stars 355 forks source link

Update batch-io sample with FlatFileItemReader #1618

Closed fmbenhassine closed 1 year ago

fmbenhassine commented 2 years ago

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?

sdeleuze commented 2 years ago

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 commented 2 years ago

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.

snicoll commented 1 year ago

Superseded by the AOT smoke tests.