You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring Boot项目启动失败求助:新手遇javax.xml.bind缺失问题

问题原因及解决方案

核心原因

启动失败的直接原因是缺少JAXB API相关类:javax/xml/bind/ValidationException。

你的项目使用的是Spring Boot 1.2.3(非常老旧的版本),它依赖的Hibernate Validator需要JAXB API完成配置属性校验,但JAXB API在Java 9及以后版本中被从JDK里移除了(日志里的java.base/jdk.internal.reflect表明你用的是Java 9+版本),运行时找不到该类,最终导致Bean创建失败。

解决方案

方案1:添加JAXB依赖(快速修复)

在pom.xml的<dependencies>块中加入以下依赖,手动引入JAXB相关类:

<dependency>
    <groupId>javax.xml.bind</groupId>
    <artifactId>jaxb-api</artifactId>
    <version>2.3.1</version>
</dependency>
<dependency>
    <groupId>com.sun.xml.bind</groupId>
    <artifactId>jaxb-impl</artifactId>
    <version>2.3.1</version>
    <scope>runtime</scope>
</dependency>
<dependency>
    <groupId>com.sun.xml.bind</groupId>
    <artifactId>jaxb-core</artifactId>
    <version>2.3.0.1</version>
</dependency>
<dependency>
    <groupId>javax.activation</groupId>
    <artifactId>activation</artifactId>
    <version>1.1.1</version>
</dependency>

方案2:升级Spring Boot版本(推荐)

Spring Boot 1.2.3是2015年的版本,存在大量兼容性问题和安全漏洞,建议升级到稳定的LTS版本(比如2.7.x系列):

  1. 修改pom.xml中的parent版本:
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.7.18</version> <!-- 最新的2.x LTS版本 -->
</parent>
  1. 更新maven-compiler-plugin配置,适配Java 8+(如果你的JDK是8+):
<plugin> 
    <artifactId>maven-compiler-plugin</artifactId> 
    <version>3.8.1</version>
    <configuration>
        <source>1.8</source>
        <target>1.8</target>
    </configuration>
</plugin>

升级后,新版本Spring Boot对Java 9+支持更好,多数依赖会自动适配,无需手动添加JAXB依赖。

内容的提问来源于stack exchange,提问作者Ganiel24

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.17 11:45:54