将SpringBoot PetClinic REST迁移到Quarkus的开源项目


SpringBoot PetClinic REST项目的GitHub存储库:https://github.com/spring-petclinic/spring-petclinic-rest
Quarkus迁移的项目的GitHub存储库:https://github.com/jonathanvila/spring-petclinic-rest/tree/quarkus
 
REST迁移
从Spring REST移到标准JAX-RS注释。

  1. @RestController --> @Path
  2. @RequestMapping --> 将其分解为下一个注释
  3. @GetMapping --> @GET
  4. @PostMapping --> @POST
  5. @PutMapping --> @PUT
  6. @DeleteMapping -> @DELETE
  7. @PathVariable -> @PathParam

 
安全迁移

  • @PreAuthorize("hasRole(@roles.ROLE_ADMIN)") 替换为
  • @RolesAllowed("ROLE_ADMIN")

添加Elytron扩展以在数据库中保持安全性:quarkus-elytron-security-JDBC扩展。在properties.file上配置这个新的扩展名
 
CORS
在application.properties文件中配置的CORS
 
指标
  1. 添加smallRye指标扩展
  2. 注释每种方法(用于自定义指标)
  3. 在属性文件中启用hibernate指标

 
验证方法迁移
  1. 将Spring验证器迁移到Hibernate验证器
  2. 从@ControllerAdvice移至JAX-RS ExceptionMapper

 
OpenAPI文件
  1. 添加扩展名“ openapi”
  2. 扩展应用程序类

 
本地缓存迁移
  1. Spring使用默认的ConcurrentHashMap
  2. Caffeine使用ConcurrentLinkedHashMap
  3. 添加“缓存”扩展名(Caffeine)并注释该方法
  4. 在属性文件中配置每个缓存行为

 
未迁移
  • Spring JDBC查询
    • 没有辅助方法可用于插入,更新
    • 不等同于org.springframework.jdbc.core类
    • 我们需要使用AGROAL重新实现所有功能
  • JMX
    • GraalVM定义不支持

 
迁移后性能比较:


         Spring Boot    Quarkus Hotspot    Quarkus GraalVM
构建       48 MB         42 MB           97 MB
          4.3 s         13 s            185 s 
     
启动       630 MB        251 MB          21 MB
          6.8 s         2.6 s           0.462 s