-
Notifications
You must be signed in to change notification settings - Fork 40.9k
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
Native image | ClassPathScanningCandidateComponentProvider not working #37396
Comments
Could it be somehow related with spring-projects/spring-framework#29163 |
I was able to fix it by adding a new entry in resource config for the classes i want to inspect with reflection. Maybe therefore this issue can be closed, or maybe PathMatchingResourcePatternResolver could be improved to highlight a little bit more that resources are being skipped. In the reproducer attached, the logs that caught my attention - after a few hours - were: After seeing it I realized that perhaps I should add files instead of annotation configurations... which seems very odd to be honest. |
You are not supposed to read class files as resources and inspect their bytecode at runtime in a native image. This defeats the purpose of native and goes against the closed world assumptions required for an efficient native image. You should instead use the AOT infrastructure to perform those operations during the AOT phase. |
Hello @bclozel. I see, it is a different kind of mindset. As a user is very confusing to understand what we must or not register since spring already does a lot of magic. I don't even know if a should open issues or just give up on native. |
That's the goal of the entire AOT engine. All Spring projects (Framework, Data, GraphQL, etc) looking at annotations at runtime and processing them for registrations or proxy generation are using the AOT engine. Sometimes it can be as easy as registering a few GraalVM reachability hints (if you're not scanning the classpath but rather getting beans from the application context). This solution only applies for Spring applications, as other libraries and frameworks might have chosen a different approach. I think that Spring Data projections should work already; maybe you're hitting a specific limitation? In any case, you should open an issue against Spring Data JPA in this case because the supporting AOT code lives there. |
Hi,
I've been trying to use native image support offered in spring boot 3.x.
Problem
When running a graalvm generated native image/executable, ClassPathScanningCandidateComponentProvider doesn't
seem to be able to find interfaces/classes with annotation.
Runnable example
More information/instructions and a runnable example are provided at https://github.com/GoncaloPT/native-annotation-find.
Versions used
spring-boot: 3.2.0-SNAPSHOT
jdk: Liberica-NIK-23.0.0-1 (build 20.0.1+10)
The text was updated successfully, but these errors were encountered: