Issue
Running Native test with SpringApplicationBuilder results in error:
java.lang.ClassNotFoundException: org.graalvm.junit.platform.NativeImageJUnitLauncher__ApplicationContextInitializer
I am trying to startup multiple applications in this test with SpringApplicationBuilder. Regular java tests are okay. But native test fails as shown above. In my understanding, ApplicationContextInitializer shouldn’t attempt to initialize for NativeImageJUnitLauncher?
I am using nativeTest profile from spring-boot-starter-parent
See below for a simplified sample application showing this behavior.
Versions Spring Boot: 3.0.6 GraalVM: 22.3.r17
Reproducer https://github.com/zhumin8/graalvm-helloworld/tree/rep-error
Comment From: wilkinsona
The main application class for a SpringApplication is deduced by walking the stack. In your case, there's no correct main method and the main method on NativeImageJUnitLauncher is being detected instead.
You may be able to get your test to work by configuring the main application class to be GraalvmHelloWorldApplication. Running a Spring Boot application in a native image requires that it is first processed ahead-of-time. Setting the main class might work out in your case as the AOT processing of your main code will cover GraalvmHelloWorldApplication which you're then using in your tests.
Unlike @SpringBootTest that should work out of the box, I don't think there's anything we can do in Spring Boot to make this work automatically. At the least, you'll have to make sure that the main application class is correctly configured. You'll also have to rely upon something else having triggered AOT processing for GraalvmHelloWorldApplication.