Spring to Quarkus
migration
Agenda
1. who am i
2. what can you expect
3. what is quarkus
4. why migrate
5. migration
a. application description
b. steps
6. performance comparative
7. summary
8. references
$ whoami
JUG leader in the BarcelonaJUG
Organiser at JBCNConf ( Barcelona )
Software Engineer at Red Hat
App. Modernisation and Migration
team
Learning to play guitar
Learning Frozen songs to sing with my
daughter.
@vilojona
jvilalop@redhat.com
aytartana.wordpress.com
github.com/jonathanvila
What can you expect ?
My experience
v 2.1.5
v 1.1.1
opinionated option
magistral lecture
something that works
THE way
Quarkus brief description
what is quarkus
A Kubernetes Native, Java, Scala, Kotlin stack
tailored for GraalVM and OpenJDK HotSpot
crafted from the best of breed Java libraries and standards.
10x faster 100x smaller focused on easy to code
opensource fast paced releases tons of extensions
Quarkus key facts
Quarkus extensions ( > 90 )
Kafka
Camel
Keycloak
Spring
Vert.x
RestEasy
….
Microprofile
Openshift
Jaegger
Flyway
Hibernate
Infinispan
...
Quarkus evolution
2018-12 v 0.0.1
2019-06 v 0.15.0
2019-11 v 1.0.0 Release
2020-01 v 1.2.0
1 minor version every 2 weeks !!! (+/-)
Quarkus performance
Quarkus OSS status
Migration of
Spring PetClinic REST
Why to migrate
My experience
with an easy CDI, REST, …
long startup times, eternal tests,
applications super big,
easy to develope applications
feeling of “lots of things happen under the
hood”
easy to develop applications,
fast
lightweight
not everything ready
Application migrated
Spring Data ( repositories, jdbc , ... )
Spring Web ( REST )
Spring Security
Spring documentation ( Swagger )
Spring actuators
Spring micrometer
Spring CDI
Hibernate Panache
JaxRS
Quarkus Security
OpenAPI
SmallRye Health
Microprofile Metrics
CDI
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
Beans activated by Profile
* no annotation built in
* feasible with methods by hand
JMX
* not supported by GraalVM definition
Method Caching
* could use Infinispan but waiting for the local cache method
CDI
● Replace Autowired by Inject
● Beans declaration using @ApplicationScope
● Auto injection on Constructors
● Lazy by default
CDI
PROs
● straight forward migration for Beans
● no feature missing
CONs
● no annotation built-in beans injection depending on Profile
● no private members on injection
JPA Repositories
● Repository classes to implement PanacheRepository<T>
Quarkus will generate the implementation of the usual methods :
list , find, persist, delete
JPA Repositories
PROs
● straightforward migration
CONs
● no Query DSL methods
Application
● Removed SpringApplication class
Quarkus doesn’t need a main entry application class
( needed to configure OpenApi )
Spring REST to JAX-RS
● Move from Spring REST to the standard JAX-RS
@RestController
@RequestMapping, @GetMapping,
@PostMapping, @PutMapping,
@DeleteMapping
@PathVariable
@Path
@GET,
@POST, @PUT
@DELETE
@PathParam
Spring REST to JAX-RS
PROs
● straightforward migration
INFO
● Spring also supports JAX-RS as 3rd party lib
Spring REST Security to Quarkus Security
● replaced Spring REST Security
Spring REST JDBC Security to Elytron JDBC realm
Add extension dependency : elytron-security-jdbc
Configure on properties file and remove configureGlobal method
Spring REST Security to Quarkus security
PROs
● Almost the same result
● By configuration rather than code
CONs
● Quarkus doesn’t have an expression language
CORS
● configured CORS in the application.properties file
CORS
PROs
● easy to enable , no code involved
CONs
● at global level, not per Controller
Metrics
● Add smallRye metrics extension
● Annotate each method ( for custom metrics )
Metrics
PROs
● OpenMetrics standard naming
CONs
● different naming than micrometer
( compatibility toggle being developed )
● not the same metrics
● no AOP so you need to annotate every
method
● hard to do metrics on super classes
Validation
● Spring Validation to Hibernate Validator
● Move from @ControllerAdvice to JAX-RS ExceptionMapper
Validation
PROs
● standard
● easy
CONs
● Spring has more MVC features
Swagger ( OpenAPI v 3.0 )
● Add extension “openapi”
● Add RestApplication
Swagger ( OpenAPI v 3.0 )
PROs
● straightforward migration
● standard and easy way to configure
● Swagger-UI OOTB
CONs
● not REST paths scan configuration
AOP for metrics on Repositories
● use of CDI interceptors
AOP for metrics on Repositories
PROs
● standard
● easy to create interceptors
CONs
● need to annotate ALL methods one by one
● no expression language to define methods affected
Test : REST
MockMVC -> RestAssured
Test REST
PROs
● RESTassured is easy to handle and looks very intuitive
CONs
● No way to simulate Roles without creating an user for each role to test
INFO
● Changed JSonPath to GPath
Test : Mocking
Create a Java class extending your real class and put it in Test folder
Tbh, I haven’t done it… I prefer to use Mockito
Test - resources
● Annotate test suites with @QuarkusTest to boot the app
● Annotate test suites with @QuarkusTestResource to load an embedded
resource
BUT……
Spring API compatible with Quarkus
Spring WEB ( REST) : spring-web extension
Using same Spring API for REST Supported Annotations
@RestController
@RequestMapping
@GetMapping
@PostMapping
@PutMapping
@DeleteMapping
@PatchMapping
@RequestParam
@RequestHeader
@MatrixVariable
@PathVariable
@CookieValue
@RequestBody
@ResponseStatus
@ExceptionHandler
Spring DI : spring-di extension
Using same API as Spring DI
Annotations Supported
@Autowired @Repository
@Qualifier @Scope
@Value @Component
* doesn’t support an expression language
@Configuration @Service
@Bean
Spring Data : spring-data-jpa
Using same API for Spring Data Supported
Any interface of : Repository,
CrudRepository, PagingAndSortingRepository,
JpaRepository
Derived Query Methods
User defined Queries
Not Supported
Invocations to any method of
QueryByExampleExecutor
QueryDSL
Spring Security: spring-security extension
Using same API as Spring Security
Annotations Supported
@Secured
@Preauthorized
Expressions allowed
hasAnyRole
permitAll
denyAll
isAnonymous
isAuthenticated
#paramName ==
Performance comparative ( not exhaustive )
SPRING QUARKUS
JVM
QUARKUS
GraalVM
build
( uber-jar )
4 s
43 Mb
13 s
43 Mb
133 s
85 Mb
boot 7.985 s
634.2 Mb
0.901 s
287.3 Mb
0.431 s
15.9 Mb
Summary
● Using specialised standard and open libraries
● Easy to code
● Full of documentation and examples
● Quarkus team/community is awesome
● Fast release cadence
● Few bugs on extensions ( but they fix them like Speedy Gonsales )
● No-reflection goal can have some limitations ( JMX, AOP … )
● Not everything has a 1:1 migration ( Query DSL Methods , … )
References
Repositories
● Spring REST PetClinic
https://github.com/spring-petclinic/spring-petclinic-
rest
● Quarkus REST PetClinic
https://github.com/jonathanvila/spring-petclinic-
rest/tree/quarkus
Documentation/News/Help
● https://quarkus.io
● @QuarkusIO
● https://developers.redhat.com/search/?t=quarkus
● quarkus-dev@googlegroups.com
Interactive Tutorials ( Katacoda )
● https://developers.redhat.com/courses/quarkus/
List of Tutorials
● Getting Started
● For Spring Devs
● Streaming with
Kafka
● Hibernate and
Panache
● Prometeus &
Grafana
Cheat Sheet
● https://lordofthejars.github.io/quarkus-cheat-sheet/
by Alex Soto
Do you want to start coding with Quarkus ?
https://code.quarkus.io/
Windup
● Opensource tool to help on applications migrations
○ https://github.com/windup
○ to cloud readyness
○ to EAP...
○ soon to Quarkus
Thank you for having the patience to attend
and also to all who have
directly or indirectly helped me on this talk.
Special thanks to :
David Gómez, Alejandro Martinez, Abel Salgado
Alex Soto, Georgios Andrianakis
and the rest of Red Hat Quarkus team

Migration Spring PetClinic to Quarkus

  • 1.
  • 2.
    Agenda 1. who ami 2. what can you expect 3. what is quarkus 4. why migrate 5. migration a. application description b. steps 6. performance comparative 7. summary 8. references
  • 3.
    $ whoami JUG leaderin the BarcelonaJUG Organiser at JBCNConf ( Barcelona ) Software Engineer at Red Hat App. Modernisation and Migration team Learning to play guitar Learning Frozen songs to sing with my daughter. @vilojona jvilalop@redhat.com aytartana.wordpress.com github.com/jonathanvila
  • 4.
    What can youexpect ? My experience v 2.1.5 v 1.1.1 opinionated option magistral lecture something that works THE way
  • 5.
  • 6.
    what is quarkus AKubernetes Native, Java, Scala, Kotlin stack tailored for GraalVM and OpenJDK HotSpot crafted from the best of breed Java libraries and standards.
  • 7.
    10x faster 100xsmaller focused on easy to code opensource fast paced releases tons of extensions Quarkus key facts
  • 8.
    Quarkus extensions (> 90 ) Kafka Camel Keycloak Spring Vert.x RestEasy …. Microprofile Openshift Jaegger Flyway Hibernate Infinispan ...
  • 9.
    Quarkus evolution 2018-12 v0.0.1 2019-06 v 0.15.0 2019-11 v 1.0.0 Release 2020-01 v 1.2.0 1 minor version every 2 weeks !!! (+/-)
  • 10.
  • 11.
  • 12.
  • 13.
    Why to migrate Myexperience with an easy CDI, REST, … long startup times, eternal tests, applications super big, easy to develope applications feeling of “lots of things happen under the hood” easy to develop applications, fast lightweight not everything ready
  • 14.
    Application migrated Spring Data( repositories, jdbc , ... ) Spring Web ( REST ) Spring Security Spring documentation ( Swagger ) Spring actuators Spring micrometer Spring CDI Hibernate Panache JaxRS Quarkus Security OpenAPI SmallRye Health Microprofile Metrics CDI
  • 15.
    Elements not migrated SpringJDBC querying * no helper methods to work with Inserts, Updates…. * no equivalent to org.springframework.jdbc.core classes * we need to reimplement everything using AGROAL Beans activated by Profile * no annotation built in * feasible with methods by hand JMX * not supported by GraalVM definition Method Caching * could use Infinispan but waiting for the local cache method
  • 16.
    CDI ● Replace Autowiredby Inject ● Beans declaration using @ApplicationScope ● Auto injection on Constructors ● Lazy by default
  • 17.
    CDI PROs ● straight forwardmigration for Beans ● no feature missing CONs ● no annotation built-in beans injection depending on Profile ● no private members on injection
  • 18.
    JPA Repositories ● Repositoryclasses to implement PanacheRepository<T> Quarkus will generate the implementation of the usual methods : list , find, persist, delete
  • 19.
    JPA Repositories PROs ● straightforwardmigration CONs ● no Query DSL methods
  • 20.
    Application ● Removed SpringApplicationclass Quarkus doesn’t need a main entry application class ( needed to configure OpenApi )
  • 21.
    Spring REST toJAX-RS ● Move from Spring REST to the standard JAX-RS @RestController @RequestMapping, @GetMapping, @PostMapping, @PutMapping, @DeleteMapping @PathVariable @Path @GET, @POST, @PUT @DELETE @PathParam
  • 22.
    Spring REST toJAX-RS PROs ● straightforward migration INFO ● Spring also supports JAX-RS as 3rd party lib
  • 23.
    Spring REST Securityto Quarkus Security ● replaced Spring REST Security
  • 24.
    Spring REST JDBCSecurity to Elytron JDBC realm Add extension dependency : elytron-security-jdbc Configure on properties file and remove configureGlobal method
  • 25.
    Spring REST Securityto Quarkus security PROs ● Almost the same result ● By configuration rather than code CONs ● Quarkus doesn’t have an expression language
  • 26.
    CORS ● configured CORSin the application.properties file
  • 27.
    CORS PROs ● easy toenable , no code involved CONs ● at global level, not per Controller
  • 28.
    Metrics ● Add smallRyemetrics extension ● Annotate each method ( for custom metrics )
  • 29.
    Metrics PROs ● OpenMetrics standardnaming CONs ● different naming than micrometer ( compatibility toggle being developed ) ● not the same metrics ● no AOP so you need to annotate every method ● hard to do metrics on super classes
  • 30.
    Validation ● Spring Validationto Hibernate Validator ● Move from @ControllerAdvice to JAX-RS ExceptionMapper
  • 31.
  • 32.
    Swagger ( OpenAPIv 3.0 ) ● Add extension “openapi” ● Add RestApplication
  • 33.
    Swagger ( OpenAPIv 3.0 ) PROs ● straightforward migration ● standard and easy way to configure ● Swagger-UI OOTB CONs ● not REST paths scan configuration
  • 34.
    AOP for metricson Repositories ● use of CDI interceptors
  • 35.
    AOP for metricson Repositories PROs ● standard ● easy to create interceptors CONs ● need to annotate ALL methods one by one ● no expression language to define methods affected
  • 36.
    Test : REST MockMVC-> RestAssured
  • 37.
    Test REST PROs ● RESTassuredis easy to handle and looks very intuitive CONs ● No way to simulate Roles without creating an user for each role to test INFO ● Changed JSonPath to GPath
  • 38.
    Test : Mocking Createa Java class extending your real class and put it in Test folder Tbh, I haven’t done it… I prefer to use Mockito
  • 39.
    Test - resources ●Annotate test suites with @QuarkusTest to boot the app ● Annotate test suites with @QuarkusTestResource to load an embedded resource
  • 40.
  • 41.
    Spring WEB (REST) : spring-web extension Using same Spring API for REST Supported Annotations @RestController @RequestMapping @GetMapping @PostMapping @PutMapping @DeleteMapping @PatchMapping @RequestParam @RequestHeader @MatrixVariable @PathVariable @CookieValue @RequestBody @ResponseStatus @ExceptionHandler
  • 42.
    Spring DI :spring-di extension Using same API as Spring DI Annotations Supported @Autowired @Repository @Qualifier @Scope @Value @Component * doesn’t support an expression language @Configuration @Service @Bean
  • 43.
    Spring Data :spring-data-jpa Using same API for Spring Data Supported Any interface of : Repository, CrudRepository, PagingAndSortingRepository, JpaRepository Derived Query Methods User defined Queries Not Supported Invocations to any method of QueryByExampleExecutor QueryDSL
  • 44.
    Spring Security: spring-securityextension Using same API as Spring Security Annotations Supported @Secured @Preauthorized Expressions allowed hasAnyRole permitAll denyAll isAnonymous isAuthenticated #paramName ==
  • 45.
    Performance comparative (not exhaustive ) SPRING QUARKUS JVM QUARKUS GraalVM build ( uber-jar ) 4 s 43 Mb 13 s 43 Mb 133 s 85 Mb boot 7.985 s 634.2 Mb 0.901 s 287.3 Mb 0.431 s 15.9 Mb
  • 46.
    Summary ● Using specialisedstandard and open libraries ● Easy to code ● Full of documentation and examples ● Quarkus team/community is awesome ● Fast release cadence ● Few bugs on extensions ( but they fix them like Speedy Gonsales ) ● No-reflection goal can have some limitations ( JMX, AOP … ) ● Not everything has a 1:1 migration ( Query DSL Methods , … )
  • 47.
    References Repositories ● Spring RESTPetClinic https://github.com/spring-petclinic/spring-petclinic- rest ● Quarkus REST PetClinic https://github.com/jonathanvila/spring-petclinic- rest/tree/quarkus Documentation/News/Help ● https://quarkus.io ● @QuarkusIO ● https://developers.redhat.com/search/?t=quarkus ● quarkus-dev@googlegroups.com
  • 48.
    Interactive Tutorials (Katacoda ) ● https://developers.redhat.com/courses/quarkus/ List of Tutorials ● Getting Started ● For Spring Devs ● Streaming with Kafka ● Hibernate and Panache ● Prometeus & Grafana
  • 49.
  • 50.
    Do you wantto start coding with Quarkus ? https://code.quarkus.io/
  • 51.
    Windup ● Opensource toolto help on applications migrations ○ https://github.com/windup ○ to cloud readyness ○ to EAP... ○ soon to Quarkus
  • 52.
    Thank you forhaving the patience to attend and also to all who have directly or indirectly helped me on this talk. Special thanks to : David Gómez, Alejandro Martinez, Abel Salgado Alex Soto, Georgios Andrianakis and the rest of Red Hat Quarkus team