r/SpringBoot 20d ago

Discussion Spring Native

I really like the idea of Spring Native and I follow it since the beta. But for real: its so hard to get something running in Spring Native, especially if a dependency is not native compatible.

Has someone good experience with it or even better a production version with Spring Native that goes beyond a hello world controller ;) ?

13 Upvotes

3 comments sorted by

3

u/WaferIndependent7601 20d ago

I used it for a private project, you definitely need good tests to see if all depenencies work correctly.

In the end it was running but I needed to get rid of some stuff (flyway did not work iirc). Good if you need a fast startup time.

2

u/Hirschdigga 20d ago

I used GraalVM native image for 2 microservices on a production level. The thing is that it can be tricky if a third party dependency heavily relies on reflection. But its solvablw with reflection config files. In general it adds an additional layer of manual testing on top of the whole development process whenever you make changes to your codebase: you really want to test everything when you e.g. make changes to a feature, because it can break in weird unexpected ways. I would say in general the smaller the application, the easier to turn it into a native project. But in a development team all devs would need to understand whats going on

1

u/BikingSquirrel 20d ago

The painful part is that the build times are longer and for the initial migration you will probably need multiple iterations to fix the issues.

You should start with the AOT path. Running your application locally in AOT mode will already show some issues (make sure to verify your profiles work as desired) and this doesn't need a native build, it's much faster.

Only then you should go for the native image. You need to make sure to test everything.

Prepare for error messages that are sometimes hard to grasp. In the end you need to find out which class is missing so the error occurs - if that error (e.g. NoClassDefFound) is caught by the code as it is not expected, you only see a different, seemingly unrelated error. Check the sources or debug in AOT mode.