This document discusses Spring Native, which allows Spring applications to be compiled to native executables using GraalVM. Some key points made:
- Spring Native provides beta support for compiling Spring apps to native images using GraalVM's native image compiler.
- Compiling to a native image results in faster startup times, lower memory usage, and better performance compared to a traditional JVM.
- However, there are some limitations in what GraalVM supports, such as dynamic class loading.
- While many Spring features work seamlessly, some like AOP and certain integrations are still in the backlog to be fully supported.
- The document provides examples of architectures that can be built with Spring Native.
2. #DevoxxUK | #SpringNative @iamsoham 2
SOHAM
DASGUPTA
Father and Football lover
Tech Enthusiast/Programmer/Architect
Speaker & Blogger
Twitter : @iamsoham
LinkedIn: dasguptasoham
Github: sohamda
Medium: @iam.soham
3. #DevoxxUK | #SpringNative @iamsoham 3
QUICK TOUR OF
Native? What is it exactly!
Ok! How to build one?
Yeah, what did we achieved
Ok, then why NOT
4. #DevoxxUK | #SpringNative @iamsoham 4
NATIVE
• JVM based code, compiled ahead-of-time to a
standalone executable.
• Results into faster startup, low memory footprint
and high performance.
• Well suited for sustainable microservice
architectures.
• The Native Image builder is a utility that
processes all classes of an application and their
dependencies, including those from the JDK.
5. #DevoxxUK | #SpringNative @iamsoham 5
SPRING NATIVE
Spring Native provides beta support for compiling Spring applications to native executables using
GraalVM native-image compiler.
7. #DevoxxUK | #SpringNative @iamsoham 7
WAIT..GRAALVM LIMITATIONS!
• Dynamic Class loading
• Class.forName(myClass)
• Reflection
• Dynamic Proxy
• java.lang.reflect.Proxy.getProxyClass(ClassLo
ader, Class<?>[])
• JNI (Java Native Interface)
• Serialization
• Class initializers
• FInalizer
• java.lang.Object.finalize()
• Also deprecated since Java 9
• Thread.stop()
• Debugging and Monitoring
• JFR
Can be managed via a config file Just not possible
https://www.graalvm.org/22.0/reference-manual/native-image/Limitations/
8. #DevoxxUK | #SpringNative @iamsoham 8
SPRING NATIVE – BACKLOG
Things are in pipeline and NOT avialable yet
• Spring Cloud Gateway
• AOP, Kafka Streams, ActiveMQ (not fully)
• Liquibase, Flyway
• Spring GraphQL, SOAP
• Log4j2, OpenFeign
• ....
• Take a look : https://github.com/spring-projects-experimental/spring-native/milestones
9. #DevoxxUK | #SpringNative @iamsoham 9
YOU CAN DO A LOT..STILL!
A larger part of your application just will run seamlessly
• Webmvc, flux
• Cloud functions
• Elastic, JDBC, JPA, Mongo, Neo4j, Hibernate
• Kafka, Streams, RabbitMQ
• Lombok
• gRPC
• Thymeleaf..
• Check out : https://github.com/spring-projects-experimental/spring-native/tree/main/samples
10. #DevoxxUK | #SpringNative @iamsoham 10
YOU CAN DO A LOT..STILL!
A sample architecture with Spring Native and GraalVM image that you can run without any issues
This executable includes the application classes, classes from its dependencies, runtime library classes, and statically linked native code from JDK. It does not run on the Java VM, but includes necessary components like memory management, thread scheduling, and so on from a different runtime system, called “Substrate VM”. Substrate VM is the name for the runtime components (like the deoptimizer, garbage collector, thread scheduling etc.). The resulting program has faster startup time and lower runtime memory overhead compared to a JVM.
The Native Image builder or native-image is a utility that processes all classes of an application and their dependencies, including those from the JDK.
Native Image uses a different way of executing Java programs than users of the Java HotSpot VM are used to. It distinguishes between image build time and image run time. At image build time, a static analysis finds all methods that are reachable from the entry point of the application. These (and only these) methods are then ahead-of-time compiled into a native image. Because of the different optimization model, Java programs can behave somewhat differently when compiled into a native image.
https://www.graalvm.org/22.0/reference-manual/native-image/Limitations/