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

3 Comments

0 votes
0 votes
0 votes

More Posts

Cavity on X-Ray: A Complete Guide to Detection and Diagnosis

Huifer - Feb 12

React Native Quote Audit - USA

kajolshah - Mar 2

The Ecosystem Conductor: Orchestrating Market Orders with Kafka, RabbitMQ and Spring Boot

rvneto - May 12

Spring Boot Large File Upload: Limits, Streaming, and Production Best Practices

buildbasekit - May 12

Building a Movie Recommendation API with Spring Boot

alejandrotg-code - Apr 28
chevron_left

Related Jobs

View all jobs →

Commenters (This Week)

3 comments
3 comments
2 comments

Contribute meaningful comments to climb the leaderboard and earn badges!