Analysis and Solutions for JAXB Dependency Missing Issues in Spring Boot Projects with Java 9 and Above

Dec 07, 2025 · Programming · 12 views · 7.8

Keywords: Spring Boot | Java 9 | JAXB Dependency | Modular System | Compatibility Issues

Abstract: This paper provides an in-depth analysis of the root cause of the javax.xml.bind.JAXBException class not found error when migrating Spring Boot projects from Java 8 to Java 9 and higher versions. The modular system introduced in Java 9 removed the JAXB API from the Java SE core library, causing frameworks like Hibernate that depend on this API to fail in Spring Boot 1.x versions. The article details Spring Boot 2.0's official support for Java 9, presents multiple solutions including adding JAXB dependencies and using JAXB runtime implementations, and discusses handling strategies for other compatibility issues such as AspectJ and Lombok. Through code examples and configuration instructions, it offers a comprehensive migration guide for developers.

Problem Background and Phenomenon Analysis

In Spring Boot development practice, many developers encounter a typical runtime error when migrating projects from Java 8 to Java 9 or higher versions: java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException. This error typically occurs during application startup, particularly when initializing the EntityManagerFactory. From the provided error log, it's evident that the root cause lies in the Hibernate framework attempting to access the JAXB API during initialization, but this API is no longer available by default in the Java 9 runtime environment.

Root Cause Investigation

Java 9 introduced a revolutionary modular system (Project Jigsaw), which has profoundly impacted the existing Java ecosystem. In Java 8 and earlier versions, the JAXB (Java Architecture for XML Binding) API was included as part of the Java SE platform in the java.xml.bind package, allowing developers to use it without additional configuration. However, starting from Java 9, Oracle decided to remove the JAXB API from the Java SE core modules, making it part of Java EE instead. This means that classes like javax.xml.bind.JAXBException are no longer available in Java 9's default classpath.

Spring Boot 1.5.x versions were primarily designed for Java 8 environments, with their auto-configuration mechanisms assuming the JAXB API would be available at runtime. When applications run in Java 9 environments, frameworks like Hibernate that depend on JAXB throw ClassNotFoundException during initialization, ultimately causing the entire application to fail startup. It's important to note that this issue is not limited to Java 9; it also exists in Java 10 and Java 11, as the removal of the JAXB API represents a permanent architectural adjustment.

Spring Boot Version Compatibility Analysis

According to Spring Boot official documentation, there are significant differences in support for Java 9 and above across different versions:

This version difference means that the best practice for solving JAXB issues depends on the Spring Boot version being used. For projects still using Spring Boot 1.x, upgrading to Spring Boot 2.x is the most reliable way to obtain complete Java 9 support.

Solutions and Implementation Steps

Solution 1: Adding JAXB API Dependency (Applicable to Java 9 and 10)

For situations where Spring Boot 1.x applications need to run in Java 9 or 10 environments, the most direct solution is to explicitly add the JAXB API dependency. Add the following dependency configuration in the Maven project's pom.xml file:

<dependency>
    <groupId>javax.xml.bind</groupId>
    <artifactId>jaxb-api</artifactId>
    <version>2.3.0</version>
</dependency>

This configuration introduces the JAXB API as an external dependency, compensating for its absence in the Java 9 runtime environment. It's important to note that in Java 9 and 10, although the java.xml.bind module has been marked as deprecated, it can still be used by adding module dependencies. In the module-info.java file, the following module declaration can be added:

requires java.xml.bind;

Solution 2: Using JAXB Runtime Implementation (Applicable to Java 11 and Above)

Starting from Java 11, the java.xml.bind module has been completely removed and no longer exists in the JDK in any form. In this case, merely adding the JAXB API dependency is insufficient; a concrete runtime implementation must also be provided. The GlassFish JAXB runtime is a widely used implementation solution:

<dependency>
    <groupId>org.glassfish.jaxb</groupId>
    <artifactId>jaxb-runtime</artifactId>
    <version>2.3.0</version>
</dependency>

In fact, from a compatibility perspective, using the JAXB runtime implementation is a safer choice even in Java 9 or 10 environments, as it doesn't depend on JDK internal modules that might be removed.

Solution 3: Upgrading to Spring Boot 2.x

For new projects or existing projects that allow major version upgrades, migrating to Spring Boot 2.x is the most thorough solution. Spring Boot 2.0 and higher versions were designed with full consideration of Java 9's modular characteristics, providing better compatibility support. Upgrade steps include:

  1. Updating the Spring Boot parent project version in pom.xml: <version>2.3.0.RELEASE</version>
  2. Checking and updating potentially incompatible dependencies
  3. Adjusting configuration properties that might be affected (many configuration properties have changed in Spring Boot 2.x)
  4. Testing the application's operation in Java 9 environments

Other Compatibility Considerations

AspectJ Version Adaptation

If the project uses AspectJ for aspect-oriented programming, version compatibility needs attention. In Java 9 environments, if there's a need to weave JDK's own classes, AspectJ 1.9 or higher must be used. Spring Boot 2.0 defaults to AspectJ 1.8, which is sufficient for most application scenarios, but in specific cases, explicit upgrading might be necessary:

<dependency>
    <groupId>org.aspectj</groupId>
    <artifactId>aspectjweaver</artifactId>
    <version>1.9.4</version>
</dependency>

Lombok Compatibility Handling

Lombok, as a popular Java library, has varying levels of support for Java 9 and above across different versions. If Lombok is used in the project and compilation or runtime issues are encountered, it's recommended to:

  1. Visit the Lombok official website to check the latest version's support for Java 9
  2. Explicitly specify a compatible Lombok version in pom.xml, overriding Spring Boot's default managed version
  3. Consider using annotation processor path configuration to ensure proper operation

Known Library Limitations

As of the writing of this article, complete support for Java 9 in certain third-party libraries is still ongoing. For example, Apache Cassandra drivers might have compatibility issues in specific versions. When selecting dependency versions, developers should consult official documentation and issue tracking systems to ensure the chosen versions explicitly support Java 9 and above.

Best Practice Recommendations

  1. Version Strategy Planning: For new projects, directly adopt Spring Boot 2.x and Java 11 LTS versions to avoid compatibility issues with intermediate versions.
  2. Dependency Management: Use Maven or Gradle's dependency management features to ensure version compatibility of all transitive dependencies.
  3. Continuous Integration Testing: Add testing tasks for different Java versions in CI/CD pipelines to identify compatibility issues early.
  4. Modularization Preparation: Even if not immediately migrating to the Java module system, begin organizing code structure in preparation for future modular migration.
  5. Monitoring Official Updates: Regularly check Spring Boot official Wiki and release notes to stay informed about the latest compatibility information and best practices.

Conclusion

The JAXB dependency missing issue encountered by Spring Boot projects in Java 9 and above versions essentially stems from ecological adjustments brought about by Java platform modularization reforms. By understanding the root cause of the problem, developers can choose solutions appropriate to their project situations: for short-term needs, adding JAXB dependencies is a quick and effective fix; for long-term maintenance projects, upgrading to Spring Boot 2.x and adopting Java 11 LTS versions is a more sustainable choice. As the Java ecosystem continues to evolve, maintaining sensitivity and adaptability to platform changes will become an important capability for modern Java developers.

Copyright Notice: All rights in this article are reserved by the operators of DevGex. Reasonable sharing and citation are welcome; any reproduction, excerpting, or re-publication without prior permission is prohibited.