-
Notifications
You must be signed in to change notification settings - Fork 696
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
Please support Spring Native hints to make it easy to turn your Exposed + Spring Boot application into GraalVM images #1274
Comments
Hi @joshlong ! I can prepare a separate module in the branch and put TypeHints from your repo there but can you advice me how to setup a test for that? Should I build some native image and run it or what? |
Hi there, so many years later, how are you? in the intervening years, we have moved on from Spring Native, which was experimental, to the Spring AOT component model, which has been part of Spring Boot 3.x since november 2022 as a GA technology, so I'd like to ask you to please consider supporting it instead of Spring Native. GraalVm offers very exciting possibilities. I've prototyped some basic support, and here's the example code - both a demo and the AOT code.
the important part is the Hints class at the bottom. We register it with Spring Boot using the
|
Hi @joshlong Thanks very much for all your effort behind this feature request and for sharing a prototype. The first error is thrown when creating any new entity instance due to these fields in EntityClass: Stacktrace (collapsed): kotlin.reflect.jvm.internal.KotlinReflectionInternalError: Could not compute caller for function
Attempting a registration like the following doesn't resolve the issue, nor does making the fields public: hints
.reflection()
.registerField(EntityClass::class.java.getDeclaredField("entityPrimaryCtor\$delegate")) Entirely avoiding reflection by providing the function manually does fix it, but we'd prefer that DAO users not have to rely on this workaround if a better option exists: class CustomerEntity(id: EntityID<Int>) : IntEntity(id) {
var name by Customers.name
val orders by OrderEntity referrersOn Orders.customerId
companion object : IntEntityClass<CustomerEntity>(
Customers,
entityCtor = { CustomerEntity(it) } // this explicit argument avoids reflection
)
} Another issue encountered when testing edge cases occurs when preloading relations, for example if one was trying to access all Orders for a collection of Customers: CustomerEntity
.all()
.with(CustomerEntity::orders)
.forEach {
println("Customer ${it.name} with orders: ${it.orders.map { o -> o.sku }}")
} Stacktrace (collapsed): kotlin.reflect.jvm.internal.KotlinReflectionInternalError: No accessors or field is found for property val
Please let me know if you have any thoughts about how to configure the |
I don't know much about the Dao approach. We could do a zoom or something to work through the code together.. should be easy enough, I'd guess. Message me josh@joshlong.com and we can setup some time? I'm in Romanian time zone until Friday. We just need some way to discover and reflect on those types at compilation time in the body a RuntimeHintsRegistrar. If the types are Spring beans, it's even easier: we can register a BeanFactoryInitializationAotProcessor, which has access to all of the BeanDefinutions and their class definitions. So we can inspect those |
Hi,
I am a big fan of Exposed. Thank you for the work you've done.
We on the Spring team are working to make it easier to support native applications with GraalVM. I use Exposed a lot for my talks so I wanted to make sure that it too would work with GraalVM native images, so I built a set of Spring Native "hints." Hints are defined as annotations and callback interfaces that generate configuration that gets fed into the GraalVM compiler to make your application work as a GraalVm native image.
If you go to the Spring Initialzr, and choose
Spring Native (Experimental)
, it'll automatically configure a build that will produce a native image for you if you runmvn -Pnative package
. The same is true for Gradle.It even supports all the major usecases of Kotlin + Spring Boot users. Well, almost all of them. I'd like for there to be Spring Native hints for Exposed.
We can't put everything in the Spring Native project. The hints are best maintained by the projects that need them. So, I put together some hints for Exposed, and I was hoping to donate them to you. You can see there's not much in the way of code - it's all annotations in this particular case, though it could become more. I confess I don't know if this will support all the Exposed cornercases. But it does work for the simple demonstration application here.
I'd love to donate that hints class (and the supporting
src/main/resources/META-INF/services/*
files) to your amazing project so that people can simply add your hints library to thespring-aot
plugins's dependencies and benefit from it.There are a few wrinkles:
Spring Native is not yet GA.
Also, I don't really know much about Gradle, so my project is all using Maven. I am hoping somebody from your team would help me add it to your project
Thanks again for your wonderful work and I hope you're all doing well
The text was updated successfully, but these errors were encountered: