The GraalVM system apparently cannot compile a Spring application into a native image.
Can we compile a subset of the Spring application -- say, as a separate library -- and then use that with the remainder compiled using the usual javac compiler?
Or maybe if we leave out some Spring features from our application?
Any other possibilities?
The opening statement of this question is a bit vague so it's hard to address it properly.
GraalVM absolutely can compile Spring applications. GraalVM distibution is very similar to a normal JDK, it includes a javac
utility, a java
utility, which can be added to the path and used normally.
You can set up the $JAVA_HOME
environment variable to point to the directory you unpacked the GraalVM distribution, add $JAVA_HOME/bin
to the path, and build Spring applications the way you usually build them, with Maven or Gradle, or any other build tools.
GraalVM can also run Spring applications, compiled both by itself and other JVMs. If you're curious, here's an example of a Spring application that not only runs on GraalVM, but also uses R to visualize a plot of the data, using GraalVM polyglot capabilities.
Now, I guess what your meant is the ability of GraalVM to create executable native images of some Java programs. Currently GraalVM cannot create native images of normal Spring applications. It is because GraalVM native image generation process has some limitations to which Java programs it can compile. Perhaps the main issue is the dynamic classloading Spring does.
Update: May 17th 2019
Here's the spring-framework's wiki page for GraalVM native image support.
The spring-graal-native experimental project, created by Andy Clement, shows how it is possible to run a Spring Boot application out of the box as a GraalVM native image. It could be used as a basis for a potential upcoming official support.
All in all, you might try it, but things might not work fully as expected.
Previous answer is below:
There's a spring-fu project, an experimental Kotlin micro-framework based on functional configuration intended to test new ideas for future Spring Boot releases, which is currently experimenting with being able to get compiled to native images by GraalVM.
At the same time, GraalVM team is investigating what can be done to simplify compiling Spring apps to native images and to support more Spring apps than currently. Some of the limitations will remain, so you'll always be able t construct a Spring app that won't work as a GraalVM native image, but perhaps you'll be able to construct Spring apps which will work too.
The exact roadmap of these changes is currently unclear.
Here's a SpringFramework issue tracker ticket that one can follow to see the development.
来源:https://stackoverflow.com/questions/50911552/graalvm-and-spring-applications