简体   繁体   中英

java.lang.NoClassDefFoundError: javax/xml/bind/DatatypeConverter while decoding JWT token with Java 11

When calling this method for decoding a JWT token javax.xml.bind.DatatypeConverter.parseBase64Binary(encoded) I get this exception:

org.springframework.web.util.NestedServletException: Handler dispatch failed; nested exception is java.lang.NoClassDefFoundError: javax/xml/bind/DatatypeConverter
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1082)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:963)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898)


Caused by: java.lang.NoClassDefFoundError: javax/xml/bind/DatatypeConverter
at io.jsonwebtoken.impl.Base64Codec.decode(Base64Codec.java:26)
at io.jsonwebtoken.impl.Base64UrlCodec.decode(Base64UrlCodec.java:78)
at io.jsonwebtoken.impl.AbstractTextCodec.decodeToString(AbstractTextCodec.java:36)
at io.jsonwebtoken.impl.DefaultJwtParser.parse(DefaultJwtParser.java:251)
at io.jsonwebtoken.impl.DefaultJwtParser.parse(DefaultJwtParser.java:481)
at io.jsonwebtoken.impl.DefaultJwtParser.parseClaimsJws(DefaultJwtParser.java:541)

I have this external libraries on the project among others:

implementation "jakarta.xml.bind:jakarta.xml.bind-api:3.0.1"
  implementation "org.glassfish.jaxb:jaxb-runtime:3.0.2"
  io.jsonwebtoken:jjwt:0.9.1
javax.xml.bind:jaxb-api:2.3.1

In the external library javax.xml.bind:jaxb-api:2.3.1 I can find the javax/xml/bind/DatatypeConverter used in the code so I don't understand why I'm getting the NoClassDefFoundError.

I use Java 11 on the project and spring boot.

Thanks for the help.

Add this line in gradle.

implementation 'javax.xml.bind:jaxb-api:2.4.0-b180830.0359'

Downgrade your javax.xml.bind:jaxb-api With specific version.

Add this class to your program for now until new versions of io.jsonwebtoken that work with jakarta are ready.

The path of this class must be io.jsonwebtoken.impl

package io.jsonwebtoken.impl;

import jakarta.xml.bind.DatatypeConverter;

public class Base64Codec extends AbstractTextCodec {
    public Base64Codec() {
    }

    public String encode(byte[] data) {
        return DatatypeConverter.printBase64Binary(data);
    }

    public byte[] decode(String encoded) {
        return DatatypeConverter.parseBase64Binary(encoded);
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM