Skip to content
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

Disable BatchTestContextCustomizer after AOT processing #4286

Closed
wants to merge 1 commit into from

Conversation

Hayvon
Copy link

@Hayvon Hayvon commented Jan 17, 2023

nativeTest not using generated testAot sources

I have created a small reproducer application with Spring Batch. It contains a simple test which is working in jvm-mode and aot mode (-Dspring.aot.enabled=true) but not when I execute nativeTest.

It fails with following message:

org.springframework.boot.test.context.SpringBootTestAnnotation@d73e98da], contextLoader = org.springframework.boot.test.context.SpringBootContextLoader, parent = null]]
       org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:142)
       org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:127)
       org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependenciesInAotMode(DependencyInjectionTestExecutionListener.java:148)
       org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:94)
       org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:241)
       [...]
     Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'batchTestContextBeanPostProcessor': Runtime reflection is not supported for public org.springframework.batch.test.context.BatchTestContextBeanPostProcessor()
       org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1306)
       org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1198)
       org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:561)
       org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:521)
       org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:326)
       [...]
     Caused by: com.oracle.svm.core.jdk.UnsupportedFeatureError: Runtime reflection is not supported for public org.springframework.batch.test.context.BatchTestContextBeanPostProcessor()
       org.graalvm.nativeimage.builder/com.oracle.svm.core.util.VMError.unsupportedFeature(VMError.java:89)
       java.base@17.0.5/java.lang.reflect.Constructor.acquireConstructorAccessor(Constructor.java:68)
       java.base@17.0.5/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:496)
       java.base@17.0.5/java.lang.reflect.Constructor.newInstance(Constructor.java:480)
       org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:197)
       [...]

This PR fixes the issue by disabling the BatchTestContextCustomizer after AOT processing

Used versions for reproducer:
Spring Boot 3.0.1
GraalVM Native Buildtools: 0.9.19
Java 17

@hpoettker
Copy link
Contributor

Will this PR be included in the upcoming 5.0.1?

That would be great! Spring Framework is working on a nicer mechanism scoped for Spring 6.1 (spring-projects/spring-framework#29484). Until then, this seems to be the right approach as it is also used in the ContextCustomizer implementations in Spring Boot.

@fmbenhassine fmbenhassine added this to the 5.0.1 milestone Feb 16, 2023
fmbenhassine pushed a commit that referenced this pull request Feb 16, 2023
@fmbenhassine
Copy link
Contributor

@hpoettker yes, I planned the fix for the upcoming 5.0.1

@Hayvon Thank you for raising the issue and fixing it! LGTM, rebased and merged as ed4a318. Thank you for your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants