While migrating from Spring Boot v2.7.14 to v3.3.2, I'm getting the below error :
ClassNotFoundException for javax.xml.bind.annotation.XmlElement
To resovle the issue I have to add the below dependency :
<!-- Additional dependencies after moving from Spring Boot v2 to v3-->
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.0</version>
</dependency>
Request
Could you please resolve the issue with the Spring Boot 3 versions of manually adding this dependency in the pom.xml?
Comment From: wilkinsona
Spring Boot 3 has a Jakarta EE 9 baseline. javax.xml.bind.annotation.XmlElement is part of Jakarta EE 8 and earlier and, generally speaking, should not be used with Spring Boot 3. If it's required by one of your application's dependencies, you would, ideally, update the dependency to a version that is Jakarta EE 9 compatible. If that's not possible, you will have to add the dependency yourself as you appear to already be doing.
Comment From: ved-asole
Below is my pom.xml, could you please conmfirm which dependency is not compatible with Jakarta EE 9 as all the versions are taken from the main spring-boot-parent repo :
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.3.2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.vedasole</groupId>
<artifactId>ekart-ecommerce-backend</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>ekart-ecommerce-backend</name>
<description>ekart-ecommerce-backend</description>
<properties>
<java.version>17</java.version>
<sonar.organization>ved-asole</sonar.organization>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<version>3.3.2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.modelmapper</groupId>
<artifactId>modelmapper</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.6.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-hateoas</artifactId>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-api</artifactId>
<version>0.11.5</version>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-impl</artifactId>
<version>0.11.5</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-jackson</artifactId>
<version>0.11.5</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.stripe</groupId>
<artifactId>stripe-java</artifactId>
<version>25.13.0</version>
</dependency>
<!-- Better Stack Java logging -->
<dependency>
<groupId>com.logtail</groupId>
<artifactId>logback-logtail</artifactId>
<version>0.3.4</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.5.6</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.5.6</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<!-- Additional dependencies after moving from Spring Boot v2 to v3-->
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
Comment From: wilkinsona
The stack trace of the ClassNotFoundException should tell you which dependency it is that's trying and failing to load javax.xml.bind.annotation.XmlElement. As mentioned in the guidelines for contributing, we prefer to use GitHub issues only for bugs and enhancements so this request doesn't belong here. Please follow up with a question on Stack Overflow that shares as much information (particularly the stack trace of the ClassNotFoundException) and, ideally, provides a minimal sample that reproduces the problem.
Comment From: ved-asole
Ok sure. Thanks for your help @wilkinsona