javaspring-bootmigrationjax-rsjava-17

jakarta.servlet.ServletException: Handler dispatch failed: java.lang.NoClassDefFoundError: com/sun/xml/bind/api/JAXBRIContext"


I'm working on spring parent-2.7.18 to 3.1.10 version migration and I'm using Java 17 version.

I'm getting below error after the migration of Spring-parent 2.x.x to 3.x.x version.

jakarta.servlet.ServletException: Handler dispatch failed: java.lang.NoClassDefFoundError: com/sun/xml/bind/api/JAXBRIContext
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1096)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:974)

Caused by: java.lang.NoClassDefFoundError: com/sun/xml/bind/api/JAXBRIContext

here I tried below dependency(Not All at a Time) in pom.xml

      <dependency>
          <groupId>jakarta.xml.bind</groupId>
          <artifactId>jakarta.xml.bind-api</artifactId>
          <version>3.0.0</version>
      </dependency>
    
      <!-- JAXB RI, Jakarta XML Binding -->
      <dependency>
          <groupId>com.sun.xml.bind</groupId>
          <artifactId>jaxb-impl</artifactId>
          <version>3.0.0</version>
          <scope>runtime</scope>
      </dependency>

    <dependency>
        <groupId>com.sun.xml.ws</groupId>
        <artifactId>rt</artifactId>
        <version>2.3.1</version>
    </dependency>


    <dependency>
        <groupId>javax.xml.bind</groupId>
        <artifactId>jaxb-api</artifactId>
        <version>2.3.1</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>javax.jws</groupId>
        <artifactId>javax.jws-api</artifactId>
        <version>1.1</version>
    </dependency>
    <dependency>
        <groupId>com.sun.xml.ws</groupId>
        <artifactId>rt</artifactId>
        <version>2.3.1</version>
    </dependency>

    <dependency>
        <groupId>javax.xml</groupId>
        <artifactId>jaxrpc-api</artifactId>
        <version>${rpc.version}</version>
    </dependency>

Solution

  • Do not mix javax with jakarta dependencies. Spring Boot 3 uses Jakarta EE 10 and you must update your application completely to use jakarta only.

    Run mvn dependency:tree to check if there is no direct or transitive javax dependency being added in your project.

    To help you migrate to Jakarta EE 10 check the Open Rewrite recipe. You can run it from Maven command line.