Skip to content

abelsromero/boot3-ready

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

  1. Uncomment @ImportRuntimeHints line from AppConfiguration

  2. Run ./gradlew nativeTest and see all tests pass.
    Or, generate image and run curl "http://localhost:8080/hello/Glovo?source=reflection" | jq successfully now.

About

Demo Sprint Boot 3 Native project

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages