Hi,
I haven't touched spring-native for a few years, and it seems to be broken even more than it used to be.
While trying to solve other related problems, I tried to run a demo app from scratch, which failed drastically.
Set up: 1. start.spring.io 2. maven, boot 3.1.0, java, jar, 17 3. dependencies: graalvm, configuration processor, devtools, lombok, jpa, validation
Outcome: 1. Jar runs fine 2. Native image doesn't:
:: Spring Boot :: (v3.1.0)
15:17:49.314 [main] ERROR org.springframework.boot.SpringApplication -- Application run failed
java.lang.IllegalArgumentException: Could not find class [com.example.demo.DemoApplication__ApplicationContextInitializer]
at org.springframework.util.ClassUtils.resolveClassName(ClassUtils.java:334)
at org.springframework.context.aot.AotApplicationContextInitializer.instantiateInitializer(AotApplicationContextInitializer.java:80)
at org.springframework.context.aot.AotApplicationContextInitializer.initialize(AotApplicationContextInitializer.java:71)
at org.springframework.context.aot.AotApplicationContextInitializer.lambda$forInitializerClasses$0(AotApplicationContextInitializer.java:61)
at org.springframework.boot.SpringApplication.applyInitializers(SpringApplication.java:606)
at org.springframework.boot.SpringApplication.prepareContext(SpringApplication.java:386)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:310)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1305)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1294)
at com.example.demo.DemoApplication.main(DemoApplication.java:10)
Caused by: java.lang.ClassNotFoundException: com.example.demo.DemoApplication__ApplicationContextInitializer
at java.base@17.0.7/java.lang.Class.forName(DynamicHub.java:1132)
at org.springframework.util.ClassUtils.forName(ClassUtils.java:284)
at org.springframework.util.ClassUtils.resolveClassName(ClassUtils.java:324)
... 9 common frames omitted
I tried using spring-core 6.0.10-SNAPSHOT as has been suggested here, with no luck. I have published the sources so you can save some time to reproduce the issue: here
Comment From: Haarolean
Related: #32918, but with java, not kotlin.
Comment From: wilkinsona
It sounds like your application hasn't been AOT-processed, perhaps because it was not built with the correct command. Did you use ./mvnw native:compile -Pnative as described in the HELP.md file of the project generated by start.spring.io?
Comment From: spring-projects-issues
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.
Comment From: Haarolean
Hi Andy, thanks for your swift reply.
Indeed, I tried to rebuild the image again, the same way with mvn clean package -Pnative, but couldn't reproduce this anymore.
Got a lot of frustration with trying to get native images working, probably haven't paid enough attention after fighting with this for days.
Thanks again!