Spring Boot 3, ready or not!?
Spring Boot 3 Native demo project.
Requirements
Currently uses SpringBoot version 3.0.0
.
Any Graal distribution 22.3+ works.
Building
Build OS dependant native image
./gradlew nativeCompile
Directly build docker image (Linux OS) with integrated Paketo Buildpacks.
./gradlew bootBuildImage
Note
|
You can find reachability metadata for dependencies in ~.gradle/native-build-tools/repositories. |
Testing & Native compilation failure
Project is build to cause a failing tests ONLY for the native build due to use of Reflection.
HelloControllerTest
passes fine in JVM.
./gradlew test
But test method shouldReturnMessageFromReflectiveInstance
will fail on native, displaying error bellow.
./gradlew nativeTest
Failures (1): JUnit Jupiter:HelloControllerTest:shouldReturnMessageFromReflectiveInstance() MethodSource [className = 'com.example.boot3ready.HelloControllerTest', methodName = 'shouldReturnMessageFromReflectiveInstance', methodParameterTypes = ''] => jakarta.servlet.ServletException: Request processing failed: java.lang.NoSuchMethodException: com.example.boot3ready.HelloService.hello(java.lang.String) org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1011) org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:895) jakarta.servlet.http.HttpServlet.service(HttpServlet.java:668) org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:880) org.springframework.test.web.servlet.TestDispatcherServlet.service(TestDispatcherServlet.java:72) [...] Caused by: java.lang.NoSuchMethodException: com.example.boot3ready.HelloService.hello(java.lang.String) java.lang.Class.getMethod(DynamicHub.java:2227) com.example.boot3ready.HelloController.reflectionInvocation(HelloController.java:43) com.example.boot3ready.HelloController.hello(HelloController.java:34) java.lang.reflect.Method.invoke(Method.java:568) org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205) [...]
Applying Hints to fix Native compilation failure
-
Uncomment
@ImportRuntimeHints
line fromAppConfiguration
-
Run
./gradlew nativeTest
and see all tests pass.
Or, generate image and runcurl "http://localhost:8080/hello/Glovo?source=reflection" | jq
successfully now.