Fix native Spring compile with @JdbiRepository
#2727
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Resolves #2694.
For every SQL object annotated with
JdbiRepository
, theJdbiRepositoryRegistrar
currently instantiates aJdbiRepositoryFactoryBean
itself and then passes a reference to itsgetObject
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 theJdbiRepositoryFactoryBean
has been built. Compilation then stops with the error messageinstance supplier is not supported
.The PR fixes this by letting
JdbiRepositoryRegistrar
register bean definitions for theJdbiRepositoryFactoryBean
s 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.