Migrating SpringBoot PetClinic REST to Quarkus
Migrating SpringBoot PetClinic REST to Quarkus
In this post, I'm going to cover my experience migrating the Spring Boot PetClinic REST application to Quarkus.
Join the DZone community and get the full member experience.Join For Free
In this post, I'm going to cover my experience migrating the Spring Boot PetClinic REST application to Quarkus, to check how hard it can be and also to see which are the metrics I obtain at the end.
This is only an experiment with an application with low complexity but touching several common libraries and concepts used by anyone that creates a Spring Boot application.
My experience developing applications using the SpringBoot framework has been:
- Tests last ages
- Artifacts generated are big
- Applications consume lots of resources
- So many things happening under the hood
- Services started without request
- Easy to code as the framework makes things simpler
- Private company opensource solution
And I read about Quarkus and it is:
- Easy to code
- Focused on GraalVM compilation
- Opensource standard libraries used
- Fast and light
So, I decided to check those claims migrating a simple project that uses SpringBoot to see if it's easy and production-ready the mind migration for someone very used to code using SpringBoot.
SpringBoot PetClinic REST project, GitHub repository: https://github.com/spring-petclinic/spring-petclinic-rest
Quarkus migrated project, GitHub repository: https://github.com/jonathanvila/spring-petclinic-rest/tree/quarkus
Elements NOT Migrated
- Spring JDBC Querying
- No helper methods to work with Inserts, Updates
- No equivalent to org.springframework.jdbc.core classes
- We need to reimplement everything using AGROAL
- Not supported by GraalVM definition
There are two ways of migrating the application:
- Option A: moving from Spring to standard libraries
- Option B: keep using Spring interfaces and not touch your code
Migration Steps Option A: to Standard libraries
This option involves moving from Spring API interfaces into new libraries as JAX-RS, Panache, Microprofile, Hibernate validation, Quarkus Security.
Move from Spring REST to the standard JAX-RS annotations.
- @RestController --> @Path
- @RequestMapping --> break it down into next annotations
- @GetMapping --> @GET
- @PostMapping --> @POST
- @PutMapping --> @PUT
- @DeleteMapping -> @DELETE
- @PathVariable -> @PathParam
- @PreAuthorize("hasRole(@roles.ROLE_ADMIN)") by
2. Add Elytron extension to persist security in the database: quarkus-elytron-security-JDBC extension.
3. Configure the extension on properties.file
- Configured CORS in the application.properties file
- Add smallRye metrics extension
- Annotate each method (for custom metrics)
- Enable Hibernate metrics in the properties file
- Spring Validation to Hibernate Validator
- Move from @ControllerAdvice to JAX-RS ExceptionMapper
- Add extension "openapi"
- Extend Application class
- Spring uses a default ConcurrentHashMap
- Caffeine uses a ConcurrentLinkedHashMap
- Add "cache" extension ( Caffeine ) and annotate the method
- Configure each cache behavior in the properties file
Migration Steps — Option B: Using Spring Interfaces
This option involves using the spring quarkus extensions, and not change your code if you are not using a not supported feature.
There are features not supported in some of the Spring extensions, so better check them if you want to use this path.
- Add spring-web extension
- Add spring-di extension
- Add spring-data-jpa extension
- Add spring-security extension
- Annotate test suites with @QuarkusTest to boot the app
- Annotate test suites with @QuarkusTestResource to load an embedded resource
- Use the quarkus-mockito dependency: quarkus-junit5-mockito
- Annotate mocks with @InjectMock
|Spring Boot||Quarkus Hotspot||Quarkus GraalVM|
Presentation at DevNexus
To Start Coding With Quarkushttps://code.quarkus.io/
Red Hat MTA (Migration Toolkit for Applications)
This is an opensource tool to help migrate an application from different sources to different targets :
- Apache Camel 2 to Apache Camel 3
- Oracle WebLogic and IBM WebSphere to JBoss EAP
- Oracle JDK to OpenJDK
- On-Prem to Cloud and container readiness
- Spring Boot to Quarkus
It consists of a rules engine and several rules ( > 1500 rules ) to statically analyze Java applications (packaged or source code) and give hints of changes to apply to move the application from the source to the target.https://developers.redhat.com/products/mta/overview https://github.com/windup
Published at DZone with permission of Jonathan Vila . See the original article here.
Opinions expressed by DZone contributors are their own.