본문 바로가기
에러 해결기록

[Spring] JWT 사용시 javax/xml/bind/DatatypeConverter 에러

by shyun00 2024. 5. 7.

현재 자바 17, 스프링 부트 3 버전을 사용하고 있다.

사용자 로그인을 처리하고 JWT를 사용하기 위해 아래 의존성을 추가해주었다.

implementation 'io.jsonwebtoken:jjwt:0.9.1'

 

그러나 JWT를 생성, 리턴하는 과정에서 javax/xml/bind/DatatypeConverter 예외가 발생했다.

 

해당 예외는 JWT를 생성하는 과정에서 javax.xml.bind.DataTypeConverter를 사용하는데, 이를 찾지 못해 발생한 에러이다.

 

JDK 11부터 관련된 Java EE 모듈이 제거되었다고 한다. (아래 공식문서 내용 참고)

Risks and Assumptions
Java EE modules
The risk of removing the Java EE modules is that applications will not compile or run if they rely on "out of the box" support in the JDK for Java EE APIs and tools. These applications will experience binary and source incompatibilities when migrating from JDK 6, 7, or 8, to JDK 9 or a later release. Generally speaking, these applications fall into one of two categories:
Standalone programs that manipulate Web Services and XML, outside of a Java EE application server.Applications that have no connection to Web Services or XML, but rely on individual classes in the Java EE APIs for general-purpose functionality. For example, some applications rely on JAXB not for XML binding, but rather, for the Base64 support offered by the class javax.xml.bind.DatatypeConverter. (Historically, this class was a better choice than the class sun.misc.Base64{Encoder,Decoder}, though better still is the class java.util.Base64 that was introduced in Java SE 8.) As another example, some applications rely on the @Generated annotation whose type, javax.annotation.Generated, is co-located with JAX-WS in JDK 9. (Applications may choose instead to rely on the type javax.annotation.processing.Generated that was introduced in Java SE 9.).

 

 

따라서 관련 의존성을 추가하고 에러가 해결됐다.

implementation 'javax.xml.bind:jaxb-api:2.3.1'