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

Fix native Spring compile with @JdbiRepository #2727

Merged
merged 1 commit into from
Oct 22, 2024

Conversation

hpoettker
Copy link
Contributor

Resolves #2694.

For every SQL object annotated with JdbiRepository, the JdbiRepositoryRegistrar currently instantiates a JdbiRepositoryFactoryBean itself and then passes a reference to its getObject method to the bean definition registry to be called at a later time by the application context.

This works fine in the standard JVM but not with AOT and GraalVM where building the native image fails if the feature is used. The problem is that in AOT mode Spring generates the bean definitions at compile time to write corresponding Java code that GraalVM can then compile. But when it tries to do so for the bean definitions generated by JdbiRepositoryRegistrar, it can't as it cannot determine how the passed instance of the JdbiRepositoryFactoryBean has been built. Compilation then stops with the error message instance supplier is not supported.

The PR fixes this by letting JdbiRepositoryRegistrar register bean definitions for the JdbiRepositoryFactoryBeans instead that Spring AOT knows how to generate explicit code for.

With this fix, a native image can be compiled (unless of course there are other issues in the application), but it does not fix the issue that the native image will fail to run unless native hints are provided for some of the JDBI classes during compilation.

Copy link

Copy link
Member

@stevenschlansker stevenschlansker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this fix!

@stevenschlansker stevenschlansker merged commit b858e84 into jdbi:master Oct 22, 2024
54 checks passed
stevenschlansker added a commit that referenced this pull request Oct 22, 2024
@hpoettker hpoettker deleted the fix-native-spring-compile branch October 22, 2024 19:59
@hpoettker
Copy link
Contributor Author

hpoettker commented Oct 22, 2024

Thanks for the quick response and for adding the change to the release notes.

Regarding the other unreleased change. 😄
Spring 5.x and Spring 6.0 have fallen out of Spring's open-source support by now. And they have recently introduced a policy change that any fixes for unsupported versions are only released for customers with commercial support. So 5.3.40 and 5.3.41 won't be published on Maven Central.

I think you should feel free to ignore any nagging CVE checkers about this. The scenario that people pull in Spring only transitively through jdbi3-spring5 seems a bit far-fetched to me.
The alternative would be build against 6.1.x, which should also be fine as changes to the module are rare.

@hgschmie
Copy link
Contributor

wow, spring is weird.

@stevenschlansker
Copy link
Member

Gotta monetize somehow! 😎

@stevenschlansker
Copy link
Member

fixed in 3.47.0

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

Successfully merging this pull request may close these issues.

"@JdbiRepository" annotated repositories are not supported in AOT mode.
3 participants