Upgrading JJWT on Spring Boot 3.3.x for GraalVM and Cloud Native

posted 1 min read

Upgrading JJWT on Spring Boot 3.3.x

This article aims to provide details on how to fix JJWT exceptions when running the Cloud Native image, built with GraalVM.

Based on recent changes, from JJWT version 0.12.7 and above, JJWT changed how builders are instantiated with reflection, please see this comment and thread if you wan't to learn more: https://github.com/jwtk/jjwt/issues/637#issuecomment-2825061536

Basically:

Note that via the merge of #989, the (not yet released) 0.12.7 version and later changes how builders are instantiated via reflection. I'm not a graal user myself, but I wanted to make a note of that here in case the changes in #989 impact graal environments.

So, if you need JJWT on recent versions of Spring Boot and wants to compile to Cloud Native with GraalVM, here's what you need to do:

Update the resources/META-INF/native-image/reflect-config.json file adding the code below (if you don't have the file yet, create one):

 {
    "name": "io.jsonwebtoken.impl.DefaultJwtHeaderBuilder$Supplier",
    "methods": [
      {
        "name": "<init>",
        "parameterTypes": []
      }
    ]
  },
  {
    "name": "io.jsonwebtoken.impl.DefaultClaimsBuilder$Supplier",
    "methods": [
      {
        "name": "<init>",
        "parameterTypes": []
      }
    ]
  },
  {
    "name": "io.jsonwebtoken.impl.security.DefaultKeyOperationBuilder$Supplier",
    "methods": [
      {
        "name": "<init>",
        "parameterTypes": []
      }
    ]
  },
  {
    "name": "io.jsonwebtoken.impl.security.DefaultKeyOperationPolicyBuilder$Supplier",
    "methods": [
      {
        "name": "<init>",
        "parameterTypes": []
      }
    ]
  }

Note that you might need more reflection configuration depending on your case.

As a resource, I'd like to keep my code as reference, here's the PR upgrading Spring Boot to version 3.5.5 and JJWT to 0.13.0 (the latest versions in the time of this writing). Find the changes here: https://github.com/ricardo-campos-org/react-typescript-todolist/pull/631

0 votes
0 votes

More Posts

Let's understand Retries in Spring Boot

Madhu - Oct 17

Designing APIs for the AI Era with Spring AI and MCP

David Lopez Felguera - Sep 22

Power Up Java with AI: Integrate LLaMA 3 Using Spring Boot

Mandeep Dhakal - Jul 30

Creating RESTful API Using Spring Boot for The First Time

didikts - Oct 14, 2024

Integrating Kafka Test Container for Local Development Environment

Amol Gote - Jun 8, 2024
chevron_left